/// <summary> /// 基于接口类型创建 /// </summary> /// <param name="interfaceType"></param> /// <returns></returns> public static ProxyOnTypeInfo CreateByInterface(Type interfaceType) { ProxyOnTypeInfo result = new ProxyOnTypeInfo(interfaceType); Type[] baseInterfaces = interfaceType.GetInterfaces(); List <Type> allTypes = new List <Type>(baseInterfaces); allTypes.Add(interfaceType); Dictionary <string, IEnumerable <IProxy> > proxiesOnMethods = new Dictionary <string, IEnumerable <IProxy> >(); allTypes.ForEach(type => { type.GetProxies().ForEach(proxy => result.AddProxyOnClass(proxy.GetType())); type.GetMethods().ForEach(method => { result.allMethods.Add(method); method.GetProxies().ForEach(proxy => { result.AddProxyOnMethod(proxy.GetType(), method); }); }); }); return(result); }
public ProxyOnTypeRuntimeInfo(IComponentManager componentManager, ProxyOnTypeInfo info) { this.Type = info.Type; this.ProxyOnClass = info.ProxyTypesOnClass .Select(x => componentManager.CreateComponent(x)) .OfType <IProxy>() .ToList(); this.ProxyOnMethodMap = new Dictionary <string, ICollection <IProxy> >(); info.ProxyTypsOnMethodMap.ForEach(item => { this.ProxyOnMethodMap[item.Key] = item.Value .Select(x => componentManager.CreateComponent(x)) .OfType <IProxy>() .ToList(); }); }
/// <summary> /// 基于普通类型创建 /// </summary> /// <param name="type"></param> /// <returns></returns> public static ProxyOnTypeInfo CreateByNormalType(Type type) { var result = new ProxyOnTypeInfo(type); type.GetProxies().ForEach(proxy => result.AddProxyOnClass(proxy.GetType())); var proxiesOnMethod = new Dictionary <string, IEnumerable <IProxy> >(); type.GetMethods() .ForEach(method => { result.allMethods.Add(method); method.GetProxies().ForEach(proxy => { result.AddProxyOnMethod(proxy.GetType(), method); }); }); return(result); }