public static T GetPropertyValueOrThrow <T>(this IProxy _in, string _propName) { try { return((T)_in.GetType().GetProperty(_propName).GetValue(_in, null)); } catch (Exception ex) { logger.Error("param: " + nameof(_in) + " Type: [" + _in.GetType() + "] - GetPropertyValueOrThrow(" + _propName + ")", ex); throw new ArgumentNullException(_propName + " not found in datasource given in input", ex); } }
public void RegisterProxy(IProxy proxy) { if (!mProxys.ContainsKey(proxy.GetType())) { mProxys.Add(proxy.GetType(), proxy); proxy.OnRegister(); } else { throw new System.ArgumentException("Type=" + proxy.GetType() + " Already Register!"); } }
public void Add(IProxy p) { lock (mLock) { Type type = p.GetType(); if (mProxies.ContainsKey(type)) { LogModule.DebugLog(type + "already exists in ProxyManager."); return; //throw new Exception(type + "already exists in ProxyManager."); } p.OnInit(); mProxies.Add(type, p); } }
public static MethodInfo GetInterfaceMethod <TInterface>(this IProxy proxy, MethodInfo method) { // Convert the class implementation method into the interface definition method. var mapping = proxy.GetType().GetTypeInfo().GetRuntimeInterfaceMap(typeof(TInterface)); for (int i = 0; i < mapping.TargetMethods.Length; i++) { if (mapping.TargetMethods[i] == method) { return(mapping.InterfaceMethods[i]); } } return(method); }
public static MethodInfo GetInterfaceMethod <TDelegate, TInterface>(this IProxy proxy, TDelegate @delegate) where TDelegate : class { var target = @delegate as Delegate; var method = target.GetMethodInfo(); // Convert the class implementation method into the interface definition method. var mapping = proxy.GetType().GetTypeInfo().GetRuntimeInterfaceMap(typeof(TInterface)); for (int i = 0; i < mapping.TargetMethods.Length; i++) { if (mapping.TargetMethods[i] == method) { return(mapping.InterfaceMethods[i]); } } return(target.GetMethodInfo()); }