public SetCustomAttribute ( System customBuilder ) : void | ||
customBuilder | System | |
return | void |
/// <summary> /// Initializes a new instance of the <see cref="MethodBuilderHelper"/> class /// with the specified parameters. /// </summary> /// <param name="typeBuilder">Associated <see cref="TypeBuilderHelper"/>.</param> /// <param name="methodBuilder">A <see cref="MethodBuilder"/></param> public MethodBuilderHelper(TypeBuilderHelper typeBuilder, MethodBuilder methodBuilder) : base(typeBuilder) { if (methodBuilder == null) throw new ArgumentNullException("methodBuilder"); _methodBuilder = methodBuilder; methodBuilder.SetCustomAttribute(Type.Assembly.BLToolkitAttribute); }
public override void DefineMembers(DefinitionContext c) { if (method != null) throw new InvalidOperationException(); method = c.GlobalType.DefineMethod("LineSpecial",MethodAttributes.Static | MethodAttributes.Public,typeof(bool),parametertypes); foreach (LinedefSpecialAttribute attribute in attributes) { Type attrtype = typeof(LinedefSpecialAttribute); Type[] argtypes = new Type [1]; argtypes[0] = typeof(int); ConstructorInfo ctor = attrtype.GetConstructor(argtypes); object[] args = new object [1]; args[0] = attribute.Number; PropertyInfo[] properties = new PropertyInfo [2]; properties[0] = attrtype.GetProperty("ActivationType"); properties[1] = attrtype.GetProperty("Repeatable"); object[] values = new object [2]; values[0] = attribute.ActivationType; values[1] = attribute.Repeatable; CustomAttributeBuilder builder = new CustomAttributeBuilder(ctor,args,properties,values); method.SetCustomAttribute(builder); } }
public static void SetCustomAttributes(MethodBuilder mb, IPersistentMap attributes) { foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes)) mb.SetCustomAttribute(cab); }
private static void AddDebuggerHiddenAttribute(MethodBuilder method) { var type = typeof(DebuggerHiddenAttribute); var customBuilder = new CustomAttributeBuilder(type.GetConstructor(new Type[0]), new object[0]); method.SetCustomAttribute(customBuilder); }
void MarkMainMethodAsSTA(MethodBuilder mainMethod) { mainMethod.SetCustomAttribute(typeof(STAThreadAttribute).GetConstructor(Type.EmptyTypes), new byte[0]); }
public void AddIterCreatorName(MethodBuilder methodBuilder, string name) { Type[] paramTypes = new Type[] { typeof(string) }; ConstructorInfo constructor = typeof(IterCreatorNameAttribute).GetConstructor(paramTypes); CustomAttributeBuilder attrBuilder = new CustomAttributeBuilder(constructor, new object[] { name }); methodBuilder.SetCustomAttribute(attrBuilder); Attribute attr = new IterCreatorNameAttribute(name); AddCustomAttribute(methodBuilder, attr); }
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute) { m_methodBuilder.SetCustomAttribute(con, binaryAttribute); }
/// <summary> /// Adds a <see cref="DebuggerHiddenAttribute"/> to a method. /// </summary> /// <param name="method">The method to add the attribute.</param> private static void AddDebuggerHiddenAttribute(MethodBuilder method) { Type attributeType = typeof(DebuggerHiddenAttribute); CustomAttributeBuilder attribute = new CustomAttributeBuilder(attributeType.GetConstructor(new Type[0]), new object[0]); method.SetCustomAttribute(attribute); }
internal void set_custom_attr (MethodBuilder mb) { CustomAttributeBuilder attr_builder; Type func_attr = typeof (JSFunctionAttribute); Type [] func_attr_enum = new Type [] {typeof (JSFunctionAttributeEnum)}; attr_builder = new CustomAttributeBuilder (func_attr.GetConstructor (func_attr_enum), new object [] {func_type}); mb.SetCustomAttribute (attr_builder); }
private void CompileIn() { CompileInGeneratingFunction(); In = utilityClass.DefineMethod(Constants.InMethodName, MethodAttributes.Public | MethodAttributes.Static); var genericParameters = declaration.TypeParameters.Any() ? In.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes; var resultType = declaration.TypeParameters.Any() ? TypeBuilder.MakeGenericType(genericParameters.ToArray()) : TypeBuilder; In.SetReturnType(FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, resultType, genericParameters, runtimeContainer)); In.SetParameters(resultType); In.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0])); var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, resultType, genericParameters, runtimeContainer); var applyMethodGenericClass = declaration.TypeParameters.Any() ? TypeBuilder.GetMethod( TypeBuilder.MakeGenericType(genericParameters), GreatestFixedPointApplyMethod) : GreatestFixedPointApplyMethod; var applyMethodGenericMethod = applyMethodGenericClass.MakeGenericMethod(fGreatestFixedPoint); var inBody = In.GetILGenerator(); inBody.Emit(OpCodes.Ldarg_0); inBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any() ? TypeBuilder.GetConstructor( InClass.MakeGenericType(genericParameters), InGeneratingFunctionConstructor) : InGeneratingFunctionConstructor); inBody.Emit(OpCodes.Callvirt, applyMethodGenericMethod); inBody.Emit(OpCodes.Ret); }
static void AddCompilerGeneratedAttribute(MethodBuilder getMethodBuilder) { var compilerGeneratedAttributeCtor = typeof (CompilerGeneratedAttribute).GetConstructor(new Type[0]); var compilerGeneratedAttribute = new CustomAttributeBuilder(compilerGeneratedAttributeCtor, new object[0]); getMethodBuilder.SetCustomAttribute(compilerGeneratedAttribute); }
private void AddOneWayAttribute(MethodBuilder builder) { ConstructorInfo info = typeof(System.Runtime.Remoting.Messaging.OneWayAttribute).GetConstructor(Type.EmptyTypes); CustomAttributeBuilder attributeBuilder = new CustomAttributeBuilder(info, new object[0]); builder.SetCustomAttribute(attributeBuilder); }
internal static void DefineCustomAttributes(MethodBuilder member, ReadOnlyCollection<AttributeAst> attributes, Parser parser, AttributeTargets attributeTargets) { if (attributes != null) { foreach (var attr in attributes) { var cabuilder = GetAttributeBuilder(parser, attr, attributeTargets); if (cabuilder != null) { member.SetCustomAttribute(cabuilder); } } } }
private void CompileIn() { In = utilityClass.DefineMethod(Constants.InMethodName, MethodAttributes.Public | MethodAttributes.Static); var genericParameters = declaration.TypeParameters.Any() ? In.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes; var inputParameter = declaration.TypeParameters.Any() ? TypeBuilder.MakeGenericType(genericParameters.ToArray()) : TypeBuilder; In.SetReturnType(FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, inputParameter, genericParameters, runtimeContainer)); In.SetParameters(inputParameter); In.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0])); var inBody = In.GetILGenerator(); var fLeastFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, inputParameter, genericParameters, runtimeContainer); inBody.Emit(OpCodes.Ldarg_0); inBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any() ? TypeBuilder.GetConstructor( OutFunction.MakeGenericType(genericParameters), OutFunctionConstructor) : OutFunctionConstructor); inBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new Type[] { fLeastFixedPoint, inputParameter }.Concat(genericParameters).ToArray())); inBody.Emit(OpCodes.Callvirt, declaration.TypeParameters.Any() ? TypeBuilder.GetMethod(inputParameter, Cata).MakeGenericMethod(fLeastFixedPoint) : Cata.MakeGenericMethod(fLeastFixedPoint)); inBody.Emit(OpCodes.Ret); }
/// <summary> /// Initializes a method. /// </summary> /// <param name="methodBuilder">The current constructor builder.</param> /// <param name="methodInfo">The <see cref="MethodInfo"/> associated with the <paramref name="methodBuilder"/>.</param> private static void InitializeMethod(MethodBuilder methodBuilder, MethodInfo methodInfo) { // Apply method attributes foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(methodInfo)) { CustomAttributeBuilder cab = CreateCustomAttributeBuilder(cad); methodBuilder.SetCustomAttribute(cab); } // Build parameters var parameters = methodInfo.GetParameters(); for (int i = 0; i < parameters.Length; ++i) { ParameterInfo parameterInfo = parameters[i]; string parameterName = string.IsNullOrEmpty(parameterInfo.Name) ? "param" + i.ToString(CultureInfo.InvariantCulture) : parameterInfo.Name; ParameterBuilder paramBuilder = methodBuilder.DefineParameter( i + 1, // 1-based index! (0 == return type) parameterInfo.Attributes, parameterName); // Apply parameter attributes foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(parameterInfo)) { CustomAttributeBuilder cab = CreateCustomAttributeBuilder(cad); paramBuilder.SetCustomAttribute(cab); } } }
private void EmitCustomAttributes(MethodBuilder methodBuilder, IEnumerable<Cci.ICustomAttribute> attributes) { foreach (var attribute in attributes) { methodBuilder.SetCustomAttribute(CreateCustomAttributeBuilder(attribute)); } }
private void CompileOut() { Out = utilityClass.DefineMethod(Constants.OutMethodName, MethodAttributes.Public | MethodAttributes.Static); var genericParameters = declaration.TypeParameters.Any() ? Out.DefineGenericParameters(declaration.TypeParameters) : TypeBuilder.EmptyTypes; var returnType = declaration.TypeParameters.Any() ? TypeBuilder.MakeGenericType(genericParameters) : TypeBuilder; var fGreatestFixedPoint = FunctorTypeMapper.Map(declaration.Type, declaration.VariableName, returnType, genericParameters, runtimeContainer); Out.SetParameters(fGreatestFixedPoint); Out.SetReturnType(returnType); Out.SetCustomAttribute(new CustomAttributeBuilder(typeof(ExtensionAttribute).GetConstructors()[0], new object[0])); var outBody = Out.GetILGenerator(); outBody.Emit(OpCodes.Ldarg_0); outBody.Emit(OpCodes.Newobj, declaration.TypeParameters.Any() ? TypeBuilder.GetConstructor( InFunction.MakeGenericType(genericParameters), InFunctionConstructor) : InFunctionConstructor); outBody.Emit(OpCodes.Call, fmap.MakeGenericMethod(new[] { returnType, fGreatestFixedPoint }.Concat(genericParameters).ToArray())); outBody.Emit(OpCodes.Call, Ana.MakeGenericMethod(new[] { fGreatestFixedPoint }.Concat(genericParameters).ToArray())); outBody.Emit(OpCodes.Ret); }
/// <summary> /// Applies attributes to the proxied method. /// </summary> /// <param name="methodBuilder">The method builder to use.</param> /// <param name="targetMethod">The proxied method.</param> /// <see cref="IProxyTypeBuilder.ProxyTargetAttributes"/> /// <see cref="IProxyTypeBuilder.MemberAttributes"/> protected virtual void ApplyMethodAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod) { foreach (object attr in GetMethodAttributes(targetMethod)) { if (attr is CustomAttributeBuilder) { methodBuilder.SetCustomAttribute((CustomAttributeBuilder)attr); } else if (attr is CustomAttributeData) { methodBuilder.SetCustomAttribute( ReflectionUtils.CreateCustomAttribute((CustomAttributeData)attr)); } else if (attr is Attribute) { methodBuilder.SetCustomAttribute( ReflectionUtils.CreateCustomAttribute((Attribute)attr)); } } ApplyMethodReturnTypeAttributes(methodBuilder, targetMethod); ApplyMethodParameterAttributes(methodBuilder, targetMethod); }
private void AddFromIdlNameAttribute(MethodBuilder methodBuild, string forIdlMethodName) { methodBuild.SetCustomAttribute( new FromIdlNameAttribute(forIdlMethodName).CreateAttributeBuilder()); }
public void EmitAttribute (MethodBuilder builder) { if (ResolveBuilder ()) builder.SetCustomAttribute (cab); }
/// <summary> /// Initializes a new instance of the <see cref="MethodBuilderHelper"/> class /// with the specified parameters. /// </summary> /// <param name="typeBuilder">Associated <see cref="TypeBuilderHelper"/>.</param> /// <param name="methodBuilder">A <see cref="MethodBuilder"/></param> /// <param name="genericArguments">Generic arguments of the method.</param> /// <param name="returnType">The return type of the method.</param> /// <param name="parameterTypes">The types of the parameters of the method.</param> internal MethodBuilderHelper( TypeBuilderHelper typeBuilder, MethodBuilder methodBuilder, Type[] genericArguments, Type returnType, Type[] parameterTypes ) : base(typeBuilder) { if (methodBuilder == null) throw new ArgumentNullException("methodBuilder"); if (genericArguments == null) throw new ArgumentNullException("genericArguments"); _methodBuilder = methodBuilder; var genArgNames = genericArguments.Select(t => t.Name).ToArray(); var genParams = methodBuilder.DefineGenericParameters(genArgNames); // Copy parameter constraints. // List<Type> interfaceConstraints = null; for (var i = 0; i < genParams.Length; i++) { genParams[i].SetGenericParameterAttributes(genericArguments[i].GenericParameterAttributes); foreach (var constraint in genericArguments[i].GetGenericParameterConstraints()) { if (constraint.IsClass) genParams[i].SetBaseTypeConstraint(constraint); else { if (interfaceConstraints == null) interfaceConstraints = new List<Type>(); interfaceConstraints.Add(constraint); } } if (interfaceConstraints != null && interfaceConstraints.Count != 0) { genParams[i].SetInterfaceConstraints(interfaceConstraints.ToArray()); interfaceConstraints.Clear(); } } // When a method contains a generic parameter we need to replace all // generic types from methodInfoDeclaration with local ones. // for (var i = 0; i < parameterTypes.Length; i++) parameterTypes[i] = TypeHelper.TranslateGenericParameters(parameterTypes[i], genParams); methodBuilder.SetParameters(parameterTypes); methodBuilder.SetReturnType(TypeHelper.TranslateGenericParameters(returnType, genParams)); // Once all generic stuff is done is it is safe to call SetCustomAttribute // methodBuilder.SetCustomAttribute(Type.Assembly.BLToolkitAttribute); }
public static void SetCustomAttributes(MethodBuilder mb, IPersistentMap attributes) { for (ISeq s = RT.seq(attributes); s != null; s = s.next()) mb.SetCustomAttribute(CreateCustomAttributeBuilder((IMapEntry)(s.first()))); }
public void AddIterCreator(MethodBuilder methodBuilder) { Type[] paramTypes = Type.EmptyTypes; ConstructorInfo constructor = typeof(IterCreatorAttribute).GetConstructor(Type.EmptyTypes); CustomAttributeBuilder attrBuilder = new CustomAttributeBuilder(constructor, new object[] {}); methodBuilder.SetCustomAttribute(attrBuilder); Attribute attr = new IterCreatorAttribute(); AddCustomAttribute(methodBuilder, attr); }