- Home /
how to reference an enum from outside a built DLL
Right, so I'm trying to build a DLL in monodevelop for a package I want to upload to the asset store, but I have an enumeration in the unity project folder who's values I want the user to choose themselves, while the rest of the code is hidden within the DLL thats trying to reference it.
Long story short, how do I reference a c# file outside of the monodevelop solution?
Answer by FortisVenaliter · May 18, 2016 at 03:58 PM
You can't. You need to do it the other way around. Put the enum in the DLL with a public modifier in a public namespace. Then, when you import the DLL into Unity, you'll be able to reference the enum.
If you can't do it that way, you'll have to use Reflection.
I need the user to be able to choose the values of the enum so I guess I'll have to use reflection. I did a quick google for it but couldn't find anything (not really sure exactly what I'm searching for though)... Could you give me an example of how I can 'reflect' the enum into the compiled dll?
You can't, but you can use the System.Reflection.Assembly class's static functions to get a list of all Assemblies in the project, then search them for the proper enum. It's really messy and not recommended, and will probably only run on Windows.
Really, though, if the user is entering the values, then you should not be using an enum. You should use a String list or array.
hmm.. that's a shame, in my case using an enum is the most ideal type for the user. Cheers for the help though! System.Reflection.Assembly will definitely come in handy at some point!