Created
October 6, 2017 17:30
-
-
Save ByronMayne/833e617db5faa500d171acba1ad54225 to your computer and use it in GitHub Desktop.
You don't have to use reflection if everything is public
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Mono.Cecil; | |
using UnityEditor; | |
using UnityEditorInternal; | |
public class TheSolution | |
{ | |
[MenuItem("The Solution/Do It...")] | |
public static void MakePublic() | |
{ | |
MakeAssemblyPublic(InternalEditorUtility.GetEditorAssemblyPath()); | |
MakeAssemblyPublic(InternalEditorUtility.GetEngineAssemblyPath()); | |
} | |
private static void MakeAssemblyPublic(string assemblyPath) | |
{ | |
AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyPath); | |
foreach(ModuleDefinition moduleDefinition in assembly.Modules) | |
{ | |
foreach(TypeDefinition typeDefinition in moduleDefinition.Types) | |
{ | |
typeDefinition.IsPublic = true; | |
foreach(MethodDefinition methodDefinition in typeDefinition.Methods) | |
{ | |
methodDefinition.IsPublic = true; | |
} | |
foreach(FieldDefinition fieldDefinition in typeDefinition.Fields) | |
{ | |
fieldDefinition.IsPublic = true; | |
} | |
foreach(PropertyDefinition propertyDefinition in typeDefinition.Properties) | |
{ | |
if(propertyDefinition.SetMethod != null) | |
{ | |
propertyDefinition.SetMethod.IsPublic = true; | |
} | |
if(propertyDefinition.GetMethod != null) | |
{ | |
propertyDefinition.GetMethod.IsPublic = true; | |
} | |
} | |
} | |
} | |
assembly.Write(assemblyPath); | |
} | |
} |
Author
ByronMayne
commented
Oct 6, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment