using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class ILRuntimeUtility : Singleton { public ILRuntime.Runtime.Enviorment.AppDomain appdomain { get { return ILLauncherProxy.Instance.appdomain; } } public void AddEvent(string modelName, string eventName, Action action) { var iType = appdomain.LoadedTypes[modelName]; var get_Instance = iType.GetMethod("get_Instance", 0); var instance = appdomain.Invoke(get_Instance, null); var type = iType.ReflectionType; var eventInfo = type.GetEvent(eventName); eventInfo.AddEventHandler(instance, action); } public void RemoveEvent(string modelName, string eventName, Action action) { var iType = appdomain.LoadedTypes[modelName]; var get_Instance = iType.GetMethod("get_Instance", 0); var instance = appdomain.Invoke(get_Instance, null); var type = iType.ReflectionType; var eventInfo = type.GetEvent(eventName); eventInfo.RemoveEventHandler(instance, action); } public void ModelInvoke(string modelName, string methodName, params object[] p) { var iType = appdomain.LoadedTypes[modelName]; var get_Instance = iType.GetMethod("get_Instance", 0); var method = iType.GetMethod(methodName, p.Length); var instance = appdomain.Invoke(get_Instance, null); appdomain.Invoke(method, instance, p); } public T ModelInvoke(string modelName, string methodName, params object[] p) { var iType = appdomain.LoadedTypes[modelName]; var get_Instance = iType.GetMethod("get_Instance", 0); var method = iType.GetMethod(methodName, p.Length); var instance = appdomain.Invoke(get_Instance, null); return (T)appdomain.Invoke(method, instance, p); } }