本文整理汇总了C#中System.Reflection.Emit.MethodBuilder.SetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder.SetCustomAttribute方法的具体用法?C# MethodBuilder.SetCustomAttribute怎么用?C# MethodBuilder.SetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.MethodBuilder
的用法示例。
在下文中一共展示了MethodBuilder.SetCustomAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MethodBuilderHelper
/// <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);
}
示例2: DefineMembers
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);
}
}
示例3: InitializeMethod
/// <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);
}
}
}
示例4: SetCustomAttributes
public static void SetCustomAttributes(MethodBuilder mb, IPersistentMap attributes)
{
foreach (CustomAttributeBuilder cab in CreateCustomAttributeBuilders(attributes))
mb.SetCustomAttribute(cab);
}
示例5: AddDebuggerHiddenAttribute
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);
}
示例6: MarkMainMethodAsSTA
void MarkMainMethodAsSTA(MethodBuilder mainMethod)
{
mainMethod.SetCustomAttribute(typeof(STAThreadAttribute).GetConstructor(Type.EmptyTypes), new byte[0]);
}
示例7: AddIterCreatorName
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);
}
示例8: EmitAttribute
public void EmitAttribute (MethodBuilder builder)
{
if (ResolveBuilder ())
builder.SetCustomAttribute (cab);
}
示例9: ApplyMethodAttributes
/// <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);
}
示例10: CompileOut
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);
}
示例11: CompileIn
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);
}
示例12: AddCompilerGeneratedAttribute
static void AddCompilerGeneratedAttribute(MethodBuilder getMethodBuilder)
{
var compilerGeneratedAttributeCtor =
typeof (CompilerGeneratedAttribute).GetConstructor(new Type[0]);
var compilerGeneratedAttribute =
new CustomAttributeBuilder(compilerGeneratedAttributeCtor, new object[0]);
getMethodBuilder.SetCustomAttribute(compilerGeneratedAttribute);
}
示例13: AddOneWayAttribute
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);
}
示例14: DefineCustomAttributes
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);
}
}
}
}
示例15: CompileIn
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);
}