Skip to content

Instantly share code, notes, and snippets.

@ByronMayne
Created October 6, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ByronMayne/833e617db5faa500d171acba1ad54225 to your computer and use it in GitHub Desktop.
Save ByronMayne/833e617db5faa500d171acba1ad54225 to your computer and use it in GitHub Desktop.
You don't have to use reflection if everything is public
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);
}
}
@ByronMayne
Copy link
Author

usingreflection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment