/// <summary>	
        /// 	대리자를 생성합니다.
        /// </summary>
        /// <param name="returnType">	대리자가 반환하는 타입입니다. </param>
        /// <param name="name">	타입의 이름입니다. </param>
        /// <param name="invokeMethodParameters">	대리자에게 위임하는 메서드의 매개변수 타입입니다. </param>
        /// <returns>	
        /// 	대리자를 생성할 때 사용하는 <see cref="TypeBuilder"/> 객체를 반환합니다.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///		매개 변수 <paramref name="name"/> 의 값이 NULL 인 경우 발생하는 예외 입니다.
        /// </exception>
        public TypeBuilder CreateDelegate(Type returnType, string name, params Type[] invokeMethodParameters)
        {
            if (name == null)
                throw new ArgumentNullException("name");

            var delegateTypeBuilder = this.CreateType(name, AttributeConstants.TypeAttribute.Delegate);
            delegateTypeBuilder.SetParent(typeof(MulticastDelegate));

            var typeBuilderExtension = new TypeBuilderExtension(this.ModuleBuilder, delegateTypeBuilder);

            var constructorBuilder = typeBuilderExtension.CreateConstructor(AttributeConstants.MethodAttribute.Public | AttributeConstants.MethodAttribute.Constructor,
                                                                            CallingConventions.Standard,
                                                                            new Type[] { typeof(string), typeof(IntPtr) });
            constructorBuilder.DefineParameter(0, ParameterAttributes.None, "object");
            constructorBuilder.DefineParameter(1, ParameterAttributes.None, "method");

            constructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            var delegateParameters = new Type[invokeMethodParameters.Length];

            for (int i = 0; i < invokeMethodParameters.Length; i++)
            {
                delegateParameters[i] = invokeMethodParameters[i];
            }

            var invokeMethodBuilder = typeBuilderExtension.CreateMethod(AttributeConstants.MethodAttribute.Public | AttributeConstants.MethodAttribute.Virtual | MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                                                                        returnType,
                                                                        "Invoke",
                                                                        delegateParameters,
                                                                        null,
                                                                        false);
            invokeMethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            return delegateTypeBuilder;
        }
Example #2
0
        /// <summary>
        ///     대리자를 생성합니다.
        /// </summary>
        /// <param name="returnType">	대리자가 반환하는 타입입니다. </param>
        /// <param name="name">	타입의 이름입니다. </param>
        /// <param name="invokeMethodParameters">	대리자에게 위임하는 메서드의 매개변수 타입입니다. </param>
        /// <returns>
        ///     대리자를 생성할 때 사용하는 <see cref="TypeBuilder"/> 객체를 반환합니다.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///		매개 변수 <paramref name="name"/> 의 값이 NULL 인 경우 발생하는 예외 입니다.
        /// </exception>
        public TypeBuilder CreateDelegate(Type returnType, string name, params Type[] invokeMethodParameters)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            var delegateTypeBuilder = this.CreateType(name, AttributeConstants.TypeAttribute.Delegate);

            delegateTypeBuilder.SetParent(typeof(MulticastDelegate));

            var typeBuilderExtension = new TypeBuilderExtension(this.ModuleBuilder, delegateTypeBuilder);

            var constructorBuilder = typeBuilderExtension.CreateConstructor(AttributeConstants.MethodAttribute.Public | AttributeConstants.MethodAttribute.Constructor,
                                                                            CallingConventions.Standard,
                                                                            new Type[] { typeof(string), typeof(IntPtr) });

            constructorBuilder.DefineParameter(0, ParameterAttributes.None, "object");
            constructorBuilder.DefineParameter(1, ParameterAttributes.None, "method");

            constructorBuilder.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            var delegateParameters = new Type[invokeMethodParameters.Length];

            for (int i = 0; i < invokeMethodParameters.Length; i++)
            {
                delegateParameters[i] = invokeMethodParameters[i];
            }

            var invokeMethodBuilder = typeBuilderExtension.CreateMethod(AttributeConstants.MethodAttribute.Public | AttributeConstants.MethodAttribute.Virtual | MethodAttributes.HideBySig | MethodAttributes.NewSlot,
                                                                        returnType,
                                                                        "Invoke",
                                                                        delegateParameters,
                                                                        null,
                                                                        false);

            invokeMethodBuilder.SetImplementationFlags(MethodImplAttributes.Runtime | MethodImplAttributes.Managed);

            return(delegateTypeBuilder);
        }
Example #3
0
        public ICodeLambda Get()
        {
            var type = new TypeBuilderExtension(null, this.TypeLambda.TypeBuilder);
            var methodAttr = this.TypeLambda.MethodAccessor.MethodAttribute | MethodAttributes.NewSlot | MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
            var method = type.CreateMethod(methodAttr, propertyBuilder.PropertyType, String.Concat("get_", propertyBuilder.Name), Type.EmptyTypes, null, false);

            propertyBuilder.SetGetMethod(method);

            return new CodeLambda(this.TypeLambda, method.GetILGenerator());
        }
Example #4
0
        public ICodeLambda Set()
        {
            var type = new TypeBuilderExtension(null, this.TypeLambda.TypeBuilder);

            var methodAttr = this.TypeLambda.MethodAccessor.MethodAttribute | MethodAttributes.NewSlot | MethodAttributes.Final | MethodAttributes.Virtual | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
            var method = type.CreateMethod(methodAttr, typeof(void), String.Concat("set_", propertyBuilder.Name), new Type[] { propertyBuilder.PropertyType }, null, false);
            method.DefineParameter(1, ParameterAttributes.HasDefault, "value");

            propertyBuilder.SetSetMethod(method);

            return new CodeLambda(this.TypeLambda, method.GetILGenerator());
        }
Example #5
0
        public IPropertyLambda Property(Type returnType, string name, CallingConventions callingConventions)
        {
            var property = new TypeBuilderExtension(this.ModuleLambda.ModuleBuilder, this.TypeBuilder)
                                                    .CreateProperty(name, PropertyAttributes.HasDefault, returnType, null, callingConventions);

            return new PropertyLambda(this, property);
        }
Example #6
0
        public ICodeLambda Method(Type returnType, string name, Type[] argumentsTypes, MethodInfo parentMethodInfo)
        {
            var method = new TypeBuilderExtension(null, this.TypeBuilder)
                            .CreateMethod(this.methodAccessor.MethodAttribute, returnType, name, argumentsTypes, null, methodAccessor.IsOverride);

            return new MethodOperand(this, method.GetILGenerator(), method.GetBaseDefinition());
        }
Example #7
0
        public ICodeLambda Constructor(IEnumerable<ParameterCriteriaMetadataInfo> parameterCriteriaMetadataInfos)
        {
            var constructorBuilder = new TypeBuilderExtension(this.ModuleLambda.ModuleBuilder, this.TypeBuilder)
                                        .CreateConstructor(this.methodAccessor.MethodAttribute, CallingConventions.HasThis, parameterCriteriaMetadataInfos);

            ResetAccessorAttributes();

            return new CodeLambda(this, constructorBuilder.GetILGenerator());
        }
Example #8
0
        public ICodeLambda Constructor(params Type[] argumentsTypes)
        {
            var constructorBuilder = new TypeBuilderExtension(this.ModuleLambda.ModuleBuilder, this.TypeBuilder)
                                        .CreateConstructor(this.methodAccessor.MethodAttribute, CallingConventions.HasThis, argumentsTypes);

            ResetAccessorAttributes();

            return new CodeLambda(this, constructorBuilder.GetILGenerator());
        }