예제 #1
0
 static public Func <Object, Object> GetFunc(string assemblyFile, string typeName, string methodName)
 {
     Console.WriteLine($"CS::GetFunc: AssemblyFile: {assemblyFile} | TypeName: {typeName} | MethodName: {methodName} ");
     try {
         var assembly = Assembly.Load(assemblyFile);
         var wrap     = ClrFuncReflectionWrap.Create(assembly, typeName, methodName);
         Console.WriteLine("CS::GetFunc::End");
         return(new Func <Object, Object>(wrap.Call));
     }
     catch (Exception exc)
     {
         Console.WriteLine($"CS::GetFunc::Exception - {exc.Message}");
         throw exc;
     }
 }
예제 #2
0
        public static ClrFuncReflectionWrap Create(Assembly assembly, String typeName, String methodName)
        {
            Console.WriteLine("CS::ClrFuncReflectionWrap::Create");
            Type startupType = assembly.GetType(typeName);

            if (startupType == null)
            {
                throw new TypeLoadException("Could not load type '" + typeName + "'");
            }

            ClrFuncReflectionWrap wrap = new ClrFuncReflectionWrap();

            wrap.instance     = System.Activator.CreateInstance(startupType);
            wrap.invokeMethod = startupType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);
            if (wrap.invokeMethod == null)
            {
                throw new System.InvalidOperationException(
                          "Unable to access the CLR method to wrap through reflection. Make sure it is a public instance method.");
            }

            return(wrap);
        }