private Type CreateCallableInterfaceFromDelegate(Type delegateType)
        {
            Type        type;
            long        count       = Interlocked.Increment(ref counter);
            TypeBuilder typeBuilder = moduleScope.ObtainDynamicModule(true).DefineType(
                string.Format("ProxyDelegate_{0}_{1}", delegateType.Name, count),
                TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Public);

            MethodInfo invoke = delegateType.GetMethod("Invoke");

            ParameterInfo[] parameters = invoke.GetParameters();

            Type returnType = invoke.ReturnType;

            Type[] parameterTypes = new Type[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                parameterTypes[i] = parameters[i].ParameterType;
            }

            typeBuilder.DefineMethod("Invoke", MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.Public,
                                     CallingConventions.HasThis, returnType, parameterTypes);

            type = typeBuilder.CreateType();
            return(type);
        }
        private static TypeBuilder CreateTypeBuilder(ModuleScope modulescope, string name, Type baseType, IEnumerable <Type> interfaces,
                                                     TypeAttributes flags, bool forceUnsigned)
        {
            bool isAssemblySigned = !forceUnsigned && !StrongNameUtil.IsAnyTypeFromUnsignedAssembly(baseType, interfaces);

            return(modulescope.ObtainDynamicModule(isAssemblySigned).DefineType(name, flags));
        }
Example #3
0
        public EasyType(ModuleScope modulescope, string name, Type baseType, Type[] interfaces, bool serializable) : this()
        {
            TypeAttributes attr = TypeAttributes.Serializable | TypeAttributes.Public;

            if (serializable)
            {
                attr |= TypeAttributes.Serializable;
            }
            bool signStrongName = this.IsAssemblySigned(baseType);

            base._typebuilder = modulescope.ObtainDynamicModule(signStrongName).DefineType(name, attr, baseType, interfaces);
        }
Example #4
0
        public EasyType(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, bool serializable) : this()
        {
            TypeAttributes flags =
                TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Serializable;

            if (serializable)
            {
                flags |= TypeAttributes.Serializable;
            }
            bool isAssemblySigned = IsAssemblySigned(baseType);

            _typebuilder = modulescope.ObtainDynamicModule(isAssemblySigned).DefineType(
                name, flags, baseType, interfaces);
        }
Example #5
0
        private Type GenerateTargetInterface(Type type)
        {
            var count       = Interlocked.Increment(ref counter);
            var dynamicName = string.Format("ProxyDelegate_{0}_{1}", type.Name, count);

            var method         = type.GetMethod("Invoke");
            var returnType     = method.ReturnType;
            var parameters     = method.GetParameters();
            var parameterTypes = parameters
                                 .Select(x => x.ParameterType)
                                 .ToArray();

            var builder = scope.ObtainDynamicModule(true)
                          .DefineType(dynamicName, TypeAttributes.Interface | TypeAttributes.Abstract | TypeAttributes.Public);

            builder.DefineMethod("Invoke", MethodAttributes.Abstract | MethodAttributes.Virtual | MethodAttributes.Public,
                                 CallingConventions.HasThis, returnType, parameterTypes);

            return(builder.CreateType());
        }
Example #6
0
		private static TypeBuilder CreateTypeBuilder(ModuleScope modulescope, string name, Type baseType, Type[] interfaces,
		                                             TypeAttributes flags, bool forceUnsigned)
		{
			bool isAssemblySigned = !forceUnsigned && !StrongNameUtil.IsAnyTypeFromUnsignedAssembly(baseType, interfaces);
			return modulescope.ObtainDynamicModule(isAssemblySigned).DefineType(name, flags);
		}
Example #7
0
 private static TypeBuilder CreateTypeBuilder(ModuleScope scope, string typeName)
 {
     return(scope.ObtainDynamicModule(true).DefineType(typeName, TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract));
 }