Exemplo n.º 1
0
        private TypeBuilder CreateProxyTypeBuilder(string name, Type baseType)
        {
            string typeName =
                String.Format("{0}_{1}", name, Guid.NewGuid().ToString("N"));

            return(DynamicProxyManager.CreateTypeBuilder(typeName, baseType));
        }
Exemplo n.º 2
0
        public Type CreateProxyType(Type baseType, params Type[] interfaces)
        {
            TypeBuilder typeBuilder =
                CreateProxyTypeBuilder(DEFAULT_PROXY_TYPE_NAME, baseType);

            DefineProxyConstructor(ReferenceData.ObjectConstructor, typeBuilder);

            DefineInterceptor(typeBuilder);

            List <Type> interfaceList = new List <Type>();

            if (interfaces != null && interfaces.Length != 0)
            {
                interfaceList.AddRange(interfaces);
            }

            Type[] intfs = interfaceList.ToArray();
            foreach (Type intf in intfs)
            {
                BuildInterfaceList(intf, interfaceList);
            }

            List <MethodInfo> proxyMethodList = new List <MethodInfo>();

            BuildInterfaceMethodList(interfaceList, proxyMethodList);
            BuildInheritClassMethodList(baseType, proxyMethodList);

            ProxyMethodBuilder proxyMethodBuilder = new ProxyMethodBuilder();

            foreach (MethodInfo method in proxyMethodList)
            {
                proxyMethodBuilder.CreateProxyMethod(method, typeBuilder);
            }

            Type proxyType = typeBuilder.CreateType();

#if DEBUG_MODE
            DynamicProxyManager.SaveAssembly();
#endif
            return(proxyType);
        }