Beispiel #1
0
        private static Type GenerateWrapperType(Type interfaceType, Type underlyingType)
        {
            TypeBuilder proxyBuilder = DynamicWrapper.ModuleBuilder.DefineType(StringUtils.FormatWith("{0}_{1}_Wrapper", (IFormatProvider)CultureInfo.InvariantCulture, (object)interfaceType.Name, (object)underlyingType.Name), TypeAttributes.Sealed, typeof(DynamicWrapperBase), new Type[1]
            {
                interfaceType
            });
            WrapperMethodBuilder wrapperMethodBuilder = new WrapperMethodBuilder(underlyingType, proxyBuilder);

            foreach (MethodInfo newMethod in TypeExtensions.GetAllMethods(interfaceType))
            {
                wrapperMethodBuilder.Generate(newMethod);
            }
            return(proxyBuilder.CreateType());
        }