/// <summary> /// merges the separated cls type with param direction: /// for inout/out parameters a ....& type is needed. /// </summary> /// <returns></returns> public Type GetParamTypeMergedDirection() { // get correct type for param direction: if (IsIn()) { return(m_paramType.GetSeparatedClsType()); } else // out or inout parameter // need a type which represents a reference to the parametertype { return(ReflectionHelper.GetByRefTypeFor(m_paramType.GetSeparatedClsType())); } }
/// <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); }
/// <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); }
/// <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); }
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); }
/// <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; }
/// <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; }
/// <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; }
/// <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; }