Example #1
0
        /// <summary>adds a method to a type, setting the attributes on the parameters</summary>
        /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
        /// <returns>the MethodBuilder for the method created</returns>
        public MethodBuilder AddMethod(TypeBuilder builder, string methodName, ParameterSpec[] parameters,
                                       TypeContainer returnType, MethodAttributes attrs)
        {
            Type[] paramTypes = new Type[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                paramTypes[i] = parameters[i].GetParamTypeMergedDirection();
            }

            MethodBuilder methodBuild = builder.DefineMethod(methodName, attrs,
                                                             returnType.GetSeparatedClsType(),
                                                             paramTypes);

            // define the paramter-names / attributes
            for (int i = 0; i < parameters.Length; i++)
            {
                DefineParameter(methodBuild, parameters[i], i + 1);
            }
            // add custom attributes for the return type
            ParameterBuilder paramBuild = CreateParamBuilderForRetParam(methodBuild);

            for (int i = 0; i < returnType.GetSeparatedAttrs().Length; i++)
            {
                paramBuild.SetCustomAttribute(returnType.GetSeparatedAttrs()[i]);
            }
            return(methodBuild);
        }
Example #2
0
        /// <summary>
        /// adds a property setter method; optinally adds a FromIdlNameAttribute,
        /// if forIdlAttributeName is != null.
        /// </summary>
        private MethodBuilder AddPropertySetterInternal(TypeBuilder builder,
                                                        string propertyName,
                                                        string forIdlSetterName,
                                                        TypeContainer propertyType,
                                                        MethodAttributes attrs)
        {
            Type          propTypeCls = propertyType.GetSeparatedClsType();
            MethodBuilder setAccessor = builder.DefineMethod("set_" + propertyName,
                                                             attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                                                             null, new System.Type[] { propTypeCls });

            ParameterBuilder valParam = setAccessor.DefineParameter(1, ParameterAttributes.None, "value");

            // add custom attributes
            for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++)
            {
                valParam.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
            }

            if (forIdlSetterName != null)
            {
                AddFromIdlNameAttribute(setAccessor, forIdlSetterName);
            }
            return(setAccessor);
        }
Example #3
0
        /// <summary>adds a constructor to a type, setting the attributes on the parameters</summary>
        /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
        /// <returns>the ConstructorBuilder for the method created</returns>
        public ConstructorBuilder AddConstructor(TypeBuilder builder, ParameterSpec[] parameters,
                                                 MethodAttributes attrs)
        {
            Type[] paramTypes = new Type[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                paramTypes[i] = parameters[i].GetParamTypeMergedDirection();
            }

            ConstructorBuilder constrBuild =
                builder.DefineConstructor(attrs, CallingConventions.Standard,
                                          paramTypes);

            // define the paramter-names / attributes
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterAttributes paramAttr  = ParameterAttributes.None;
                ParameterBuilder    paramBuild =
                    constrBuild.DefineParameter(i + 1, paramAttr,
                                                parameters[i].GetPramName());
                // custom attribute spec
                TypeContainer specType = parameters[i].GetParamType();
                for (int j = 0; j < specType.GetSeparatedAttrs().Length; j++)
                {
                    paramBuild.SetCustomAttribute(specType.GetSeparatedAttrs()[j]);
                }
            }

            return(constrBuild);
        }
Example #4
0
        /// <summary>adds a field to a type, including the custom attributes needed</summary>
        /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
        /// <returns>the FieldBuilder for the field created</returns>
        public FieldBuilder AddFieldWithCustomAttrs(TypeBuilder builder, string fieldName,
                                                    TypeContainer fieldType, FieldAttributes attrs)
        {
            // consider custom mappings
            Type         clsType    = fieldType.GetSeparatedClsType();
            FieldBuilder fieldBuild = builder.DefineField(fieldName, clsType, attrs);

            // add custom attributes
            for (int j = 0; j < fieldType.GetSeparatedAttrs().Length; j++)
            {
                fieldBuild.SetCustomAttribute(fieldType.GetSeparatedAttrs()[j]);
            }
            return(fieldBuild);
        }
Example #5
0
        /// <summary>
        /// reefines a prameter; not possible for return parameter, ...? TODO: refact ...
        /// </summary>
        /// <param name="methodBuild"></param>
        /// <param name="spec"></param>
        /// <param name="paramNr"></param>
        private void DefineParameter(MethodBuilder methodBuild, ParameterSpec spec, int paramNr)
        {
            ParameterAttributes paramAttr = ParameterAttributes.None;

            if (spec.IsOut())
            {
                paramAttr = paramAttr | ParameterAttributes.Out;
            }
            ParameterBuilder paramBuild = methodBuild.DefineParameter(paramNr, paramAttr, spec.GetPramName());
            // custom attribute spec
            TypeContainer specType = spec.GetParamType();

            for (int i = 0; i < specType.GetSeparatedAttrs().Length; i++)
            {
                paramBuild.SetCustomAttribute(specType.GetSeparatedAttrs()[i]);
            }
        }
Example #6
0
        private MethodBuilder AddPropertyGetterInternal(TypeBuilder builder, string propertyName,
                                                        string forIdlGetterName,
                                                        TypeContainer propertyType, MethodAttributes attrs)
        {
            Type          propTypeCls = propertyType.GetSeparatedClsType();
            MethodBuilder getAccessor = builder.DefineMethod("get_" + propertyName,
                                                             attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
                                                             propTypeCls, System.Type.EmptyTypes);

            ParameterBuilder retParamGet = CreateParamBuilderForRetParam(getAccessor);

            // add custom attributes
            for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++)
            {
                retParamGet.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
            }
            if (forIdlGetterName != null)
            {
                AddFromIdlNameAttribute(getAccessor, forIdlGetterName);
            }
            return(getAccessor);
        }
Example #7
0
        /// <summary>
        /// adds a property to a type, including the custom attributes needed.
        /// </summary>
        public PropertyBuilder AddProperty(TypeBuilder builder, string propertyName,
                                           TypeContainer propertyType,
                                           MethodBuilder getAccessor, MethodBuilder setAccessor)
        {
            Type            propTypeCls = propertyType.GetSeparatedClsType();
            PropertyBuilder propBuild   = builder.DefineProperty(propertyName, PropertyAttributes.None,
                                                                 propTypeCls, System.Type.EmptyTypes);

            // add accessor methods
            if (getAccessor != null)
            {
                propBuild.SetGetMethod(getAccessor);
            }
            if (setAccessor != null)
            {
                propBuild.SetSetMethod(setAccessor);
            }
            // define custom attributes
            for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++)
            {
                propBuild.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
            }
            return(propBuild);
        }
 /// <summary>
 /// adds a property to a type, including the custom attributes needed.
 /// </summary>
 public PropertyBuilder AddProperty(TypeBuilder builder, string propertyName, 
                                    TypeContainer propertyType, 
                                    MethodBuilder getAccessor, MethodBuilder setAccessor) {
     Type propTypeCls = propertyType.GetSeparatedClsType();
     PropertyBuilder propBuild = builder.DefineProperty(propertyName, PropertyAttributes.None, 
                                                        propTypeCls, System.Type.EmptyTypes);
     // add accessor methods
     if (getAccessor != null) {
         propBuild.SetGetMethod(getAccessor);
     }            
     if (setAccessor != null) {
         propBuild.SetSetMethod(setAccessor);
     }
     // define custom attributes
     for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++) {
         propBuild.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);                
     }
     return propBuild;
 }
 private MethodBuilder AddPropertyGetterInternal(TypeBuilder builder, string propertyName,
                                                string forIdlGetterName, 
                                                TypeContainer propertyType, MethodAttributes attrs) {
     Type propTypeCls = propertyType.GetSeparatedClsType();
     MethodBuilder getAccessor = builder.DefineMethod("get_" + propertyName, 
                                                      attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName, 
                                                      propTypeCls, System.Type.EmptyTypes);
     
     ParameterBuilder retParamGet = CreateParamBuilderForRetParam(getAccessor);
     // add custom attributes
     for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++) {                
         retParamGet.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
     }
     if (forIdlGetterName != null) {
         AddFromIdlNameAttribute(getAccessor, forIdlGetterName);    
     }
     return getAccessor;                                                           
 }
Example #10
0
 /// <summary>
 /// adds a property setter method; optinally adds a FromIdlNameAttribute,
 /// if forIdlAttributeName is != null.
 /// </summary>
 private MethodBuilder AddPropertySetterInternal(TypeBuilder builder,
                                                 string propertyName,
                                                 string forIdlSetterName, 
                                                 TypeContainer propertyType, 
                                                 MethodAttributes attrs) {
     Type propTypeCls = propertyType.GetSeparatedClsType();
     MethodBuilder setAccessor = builder.DefineMethod("set_" + propertyName, 
                                                      attrs | MethodAttributes.HideBySig | MethodAttributes.SpecialName, 
                                                      null, new System.Type[] { propTypeCls });
     
     ParameterBuilder valParam = setAccessor.DefineParameter(1, ParameterAttributes.None, "value"); 
     // add custom attributes
     for (int j = 0; j < propertyType.GetSeparatedAttrs().Length; j++) {
         valParam.SetCustomAttribute(propertyType.GetSeparatedAttrs()[j]);
     }
     
     if (forIdlSetterName != null) {
         AddFromIdlNameAttribute(setAccessor, forIdlSetterName);    
     }            
     return setAccessor;                                                                                                                                    
 }
Example #11
0
 /// <summary>adds a field to a type, including the custom attributes needed</summary>
 /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
 /// <returns>the FieldBuilder for the field created</returns>
 public FieldBuilder AddFieldWithCustomAttrs(TypeBuilder builder, string fieldName, 
                                             TypeContainer fieldType, FieldAttributes attrs) {
     // consider custom mappings
     Type clsType = fieldType.GetSeparatedClsType();
     FieldBuilder fieldBuild = builder.DefineField(fieldName, clsType, attrs);
     // add custom attributes
     for (int j = 0; j < fieldType.GetSeparatedAttrs().Length; j++) {
         fieldBuild.SetCustomAttribute(fieldType.GetSeparatedAttrs()[j]);
     }
     return fieldBuild;
 }
Example #12
0
 /// <summary>adds a method to a type, setting the attributes on the parameters</summary>
 /// <remarks>forgeign method: should be better on TypeBuilder, but not possible</remarks>
 /// <returns>the MethodBuilder for the method created</returns>
 public MethodBuilder AddMethod(TypeBuilder builder, string methodName, ParameterSpec[] parameters, 
                                TypeContainer returnType, MethodAttributes attrs) {
 
     Type[] paramTypes = new Type[parameters.Length];
     for (int i = 0; i < parameters.Length; i++) { 
         paramTypes[i] = parameters[i].GetParamTypeMergedDirection();
     }
 
     MethodBuilder methodBuild = builder.DefineMethod(methodName, attrs, 
                                                      returnType.GetSeparatedClsType(),
                                                      paramTypes);
     // define the paramter-names / attributes
     for (int i = 0; i < parameters.Length; i++) {
         DefineParameter(methodBuild, parameters[i], i+1);
     }
     // add custom attributes for the return type
     ParameterBuilder paramBuild = CreateParamBuilderForRetParam(methodBuild);
     for (int i = 0; i < returnType.GetSeparatedAttrs().Length; i++) {
         paramBuild.SetCustomAttribute(returnType.GetSeparatedAttrs()[i]);
     }
     return methodBuild;
 }