本文整理汇总了C#中CustomAttributeBuilder.GetConstructorArgument方法的典型用法代码示例。如果您正苦于以下问题:C# CustomAttributeBuilder.GetConstructorArgument方法的具体用法?C# CustomAttributeBuilder.GetConstructorArgument怎么用?C# CustomAttributeBuilder.GetConstructorArgument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CustomAttributeBuilder
的用法示例。
在下文中一共展示了CustomAttributeBuilder.GetConstructorArgument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetAttribute
internal void SetAttribute(CustomAttributeBuilder cab)
{
Universe u = cab.Constructor.Module.universe;
Type type = cab.Constructor.DeclaringType;
if (copyright == null && type == u.System_Reflection_AssemblyCopyrightAttribute)
{
copyright = (string)cab.GetConstructorArgument(0);
}
else if (trademark == null && type == u.System_Reflection_AssemblyTrademarkAttribute)
{
trademark = (string)cab.GetConstructorArgument(0);
}
else if (product == null && type == u.System_Reflection_AssemblyProductAttribute)
{
product = (string)cab.GetConstructorArgument(0);
}
else if (company == null && type == u.System_Reflection_AssemblyCompanyAttribute)
{
company = (string)cab.GetConstructorArgument(0);
}
else if (description == null && type == u.System_Reflection_AssemblyDescriptionAttribute)
{
description = (string)cab.GetConstructorArgument(0);
}
else if (title == null && type == u.System_Reflection_AssemblyTitleAttribute)
{
title = (string)cab.GetConstructorArgument(0);
}
else if (informationalVersion == null && type == u.System_Reflection_AssemblyInformationalVersionAttribute)
{
informationalVersion = (string)cab.GetConstructorArgument(0);
}
else if (culture == null && type == u.System_Reflection_AssemblyCultureAttribute)
{
culture = (string)cab.GetConstructorArgument(0);
}
else if (fileVersion == null && type == u.System_Reflection_AssemblyFileVersionAttribute)
{
fileVersion = (string)cab.GetConstructorArgument(0);
}
}
示例2: WriteMarshallingDescriptor
private static int WriteMarshallingDescriptor(ModuleBuilder module, CustomAttributeBuilder attribute)
{
UnmanagedType unmanagedType;
object val = attribute.GetConstructorArgument(0);
if (val is short)
{
unmanagedType = (UnmanagedType)(short)val;
}
else if (val is int)
{
unmanagedType = (UnmanagedType)(int)val;
}
else
{
unmanagedType = (UnmanagedType)val;
}
ByteBuffer bb = new ByteBuffer(5);
bb.WriteCompressedUInt((int)unmanagedType);
if (unmanagedType == UnmanagedType.LPArray)
{
UnmanagedType arraySubType = attribute.GetFieldValue<UnmanagedType>("ArraySubType") ?? NATIVE_TYPE_MAX;
bb.WriteCompressedUInt((int)arraySubType);
int? sizeParamIndex = attribute.GetFieldValue<short>("SizeParamIndex");
int? sizeConst = attribute.GetFieldValue<int>("SizeConst");
if (sizeParamIndex != null)
{
bb.WriteCompressedUInt(sizeParamIndex.Value);
if (sizeConst != null)
{
bb.WriteCompressedUInt(sizeConst.Value);
bb.WriteCompressedUInt(1); // flag that says that SizeParamIndex was specified
}
}
else if (sizeConst != null)
{
bb.WriteCompressedUInt(0); // SizeParamIndex
bb.WriteCompressedUInt(sizeConst.Value);
bb.WriteCompressedUInt(0); // flag that says that SizeParamIndex was not specified
}
}
else if (unmanagedType == UnmanagedType.SafeArray)
{
VarEnum? safeArraySubType = attribute.GetFieldValue<VarEnum>("SafeArraySubType");
if (safeArraySubType != null)
{
bb.WriteCompressedUInt((int)safeArraySubType);
Type safeArrayUserDefinedSubType = (Type)attribute.GetFieldValue("SafeArrayUserDefinedSubType");
if (safeArrayUserDefinedSubType != null)
{
WriteType(module, bb, safeArrayUserDefinedSubType);
}
}
}
else if (unmanagedType == UnmanagedType.ByValArray)
{
bb.WriteCompressedUInt(attribute.GetFieldValue<int>("SizeConst") ?? 1);
UnmanagedType? arraySubType = attribute.GetFieldValue<UnmanagedType>("ArraySubType");
if (arraySubType != null)
{
bb.WriteCompressedUInt((int)arraySubType);
}
}
else if (unmanagedType == UnmanagedType.ByValTStr)
{
bb.WriteCompressedUInt(attribute.GetFieldValue<int>("SizeConst").Value);
}
else if (unmanagedType == UnmanagedType.Interface
|| unmanagedType == UnmanagedType.IDispatch
|| unmanagedType == UnmanagedType.IUnknown)
{
int? iidParameterIndex = attribute.GetFieldValue<int>("IidParameterIndex");
if (iidParameterIndex != null)
{
bb.WriteCompressedUInt(iidParameterIndex.Value);
}
}
else if (unmanagedType == UnmanagedType.CustomMarshaler)
{
bb.WriteCompressedUInt(0);
bb.WriteCompressedUInt(0);
string marshalType = (string)attribute.GetFieldValue("MarshalType");
if (marshalType != null)
{
WriteString(bb, marshalType);
}
else
{
WriteType(module, bb, (Type)attribute.GetFieldValue("MarshalTypeRef"));
}
WriteString(bb, (string)attribute.GetFieldValue("MarshalCookie") ?? "");
}
return module.Blobs.Add(bb);
}
示例3: SetCustomAttribute
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
{
Universe u = this.Module.universe;
if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_FieldOffsetAttribute)
{
customBuilder = customBuilder.DecodeBlob(this.Module.Assembly);
SetOffset((int)customBuilder.GetConstructorArgument(0));
}
else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute)
{
MarshalSpec.SetMarshalAsAttribute(typeBuilder.ModuleBuilder, pseudoToken, customBuilder);
attribs |= FieldAttributes.HasFieldMarshal;
}
else if (customBuilder.Constructor.DeclaringType == u.System_NonSerializedAttribute)
{
attribs |= FieldAttributes.NotSerialized;
}
else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
{
attribs |= FieldAttributes.SpecialName;
}
else
{
typeBuilder.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder);
}
}
示例4: SetStructLayoutPseudoCustomAttribute
private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
{
object val = customBuilder.GetConstructorArgument(0);
LayoutKind layout;
if (val is short)
{
layout = (LayoutKind)(short)val;
}
else
{
layout = (LayoutKind)val;
}
int? pack = (int?)customBuilder.GetFieldValue("Pack");
int? size = (int?)customBuilder.GetFieldValue("Size");
if (pack.HasValue || size.HasValue)
{
ClassLayoutTable.Record rec = new ClassLayoutTable.Record();
rec.PackingSize = (short)(pack ?? 0);
rec.ClassSize = size ?? 0;
rec.Parent = token;
this.ModuleBuilder.ClassLayout.AddOrReplaceRecord(rec);
}
attribs &= ~TypeAttributes.LayoutMask;
switch (layout)
{
case LayoutKind.Auto:
attribs |= TypeAttributes.AutoLayout;
break;
case LayoutKind.Explicit:
attribs |= TypeAttributes.ExplicitLayout;
break;
case LayoutKind.Sequential:
attribs |= TypeAttributes.SequentialLayout;
break;
}
CharSet? charSet = customBuilder.GetFieldValue<CharSet>("CharSet");
attribs &= ~TypeAttributes.StringFormatMask;
switch (charSet ?? CharSet.None)
{
case CharSet.None:
case CharSet.Ansi:
attribs |= TypeAttributes.AnsiClass;
break;
case CharSet.Auto:
attribs |= TypeAttributes.AutoClass;
break;
case CharSet.Unicode:
attribs |= TypeAttributes.UnicodeClass;
break;
}
}