Exemple #1
0
        protected virtual MethodBuilder DefineMethod(TypeBuilder type,
                         string name,
                         MethodAttributes attributes,
                         TypeData returnType,
                         TypedNodeList arguments)
        {
            MethodBuilder method =
                type.DefineMethod(name,
                                  attributes,
                                  returnType.RawType,
                                  arguments.NodeTypes);
            ParameterInfo[] parameters = new ParameterInfo[arguments.Length];
            ArrayList parameterList = new ArrayList();
            foreach (Argument arg in arguments) {
                ParameterAttributes attrs = 0;
                switch (arg.Mode) {
                case ArgumentMode.Out:
                    attrs |= ParameterAttributes.Out;
                    break;
                case ArgumentMode.InOut:
                    attrs |= ParameterAttributes.In;
                    attrs |= ParameterAttributes.Out;
                    break;
                }
                ParameterBuilder pb =
                    method.DefineParameter(arg.Index, attrs, arg.Name);
                Type[] cparamTypes = new Type[] { typeof(ArgumentMode) };
                ConstructorInfo constructor =
                    typeof(ArgumentModeAttribute).GetConstructor(cparamTypes);
                CustomAttributeBuilder cbuilder =
                    new CustomAttributeBuilder(constructor,
                                               new object[] { arg.Mode });
                pb.SetCustomAttribute(cbuilder);
                parameters[arg.Index - 1] =
                    new Parameter(pb, arg.NodeType.RawType, method);
                ArgumentModeAttribute attr =
                    new ArgumentModeAttribute(arg.Mode);
                typeManager.AddCustomAttribute(parameters[arg.Index - 1], attr);

                UserDefinedParameterData paramData =
                    new UserDefinedParameterData(typeManager,
                                                 parameters[arg.Index - 1],
                                                 arg.Mode);
                parameterList.Add(paramData);
            }
            UserDefinedMethodData methodData =
                typeManager.AddMethod(type, method);
            typeManager.AddParameters(method, parameters);
            methodData.Parameters = parameterList;
            return method;
        }
Exemple #2
0
 protected virtual ConstructorBuilder DefineConstructor(TypeBuilder type,
                       MethodAttributes attributes,
                       CallingConventions callingConventions,
                       Type[] paramTypes)
 {
     ConstructorBuilder constructor =
         type.DefineConstructor(attributes,
                                callingConventions,
                                paramTypes);
     ParameterInfo[] parameters = new ParameterInfo[paramTypes.Length];
     ArrayList parameterList = new ArrayList();
     for (int i = 0; i < parameters.Length; i++) {
         ParameterBuilder pb =
             constructor.DefineParameter(i + 1, 0, null);
         parameters[i] =
             new Parameter(pb, paramTypes[i], constructor);
         UserDefinedParameterData paramData =
             new UserDefinedParameterData(typeManager,
                                          parameters[i],
                                          ArgumentMode.In);
         parameterList.Add(paramData);
     }
     UserDefinedConstructorData constructorData =
         typeManager.AddConstructor(type, constructor);
     typeManager.AddParameters(constructor, parameters);
     constructorData.Parameters = parameterList;
     return constructor;
 }