Use assembly class without the assembly object

前提是你 提交于 2019-12-12 02:18:32

问题


I currently load C# code which I have compiled into a DLL using the Assembly class:

private void LoadAssembly()
        {
            try
            {
                Assembly loadedAssembly =  Assembly.LoadFrom("E:/MyUtilities/bin/Debug/MyUtilities.dll");


                System.Type type = loadedAssembly.GetType("DLLTest.MyUtilities");

                FieldInfo field = type.GetField("c");               

                Debug.Log(field.GetValue(null));

            }
            catch (System.Exception e)
            {
                Debug.Log( e.ToString() );

            }
        }

This is in a Unity game. It works fine. But I want to load the class into the loading application's domain directly. I want to do:

Debug.Log(DLLTest.MyUtilities.c)

I do not want to use the assembly object each time to access something in the DLL. Is this possible?

Basically like merging the namespaces and classes of the assembly into the application's code base so I can use classes from the assembly like I would any class defined in the application directly.

来源:https://stackoverflow.com/questions/42466027/use-assembly-class-without-the-assembly-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!