本文整理汇总了C#中CustomAttributeBuilder.GetFieldValue方法的典型用法代码示例。如果您正苦于以下问题:C# CustomAttributeBuilder.GetFieldValue方法的具体用法?C# CustomAttributeBuilder.GetFieldValue怎么用?C# CustomAttributeBuilder.GetFieldValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CustomAttributeBuilder
的用法示例。
在下文中一共展示了CustomAttributeBuilder.GetFieldValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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;
}
}