本文整理汇总了C#中Internal.TypeSystem.TypeDesc.GetField方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc.GetField方法的具体用法?C# TypeDesc.GetField怎么用?C# TypeDesc.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal.TypeSystem.TypeDesc
的用法示例。
在下文中一共展示了TypeDesc.GetField方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetFieldAccessMetadataForNativeFormatType
/// <summary>
/// Locate field on native format type and fill in the field access flags and offset.
/// </summary>
/// <param name="type">Metadata reader for the declaring type</param>
/// <param name="fieldName">Field name</param>
/// <param name="fieldAccessMetadata">Output - metadata information for field accessor construction</param>
/// <returns>true when found, false otherwise</returns>
private static bool TryGetFieldAccessMetadataForNativeFormatType(
TypeDesc type,
string fieldName,
ref FieldAccessMetadata fieldAccessMetadata)
{
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
FieldDesc fieldDesc = type.GetField(fieldName);
if (fieldDesc == null)
{
return false;
}
fieldAccessMetadata.MappingTableModule = IntPtr.Zero;
#if SUPPORTS_R2R_LOADING
fieldAccessMetadata.MappingTableModule = ModuleList.Instance.GetModuleForMetadataReader(((NativeFormatType)type.GetTypeDefinition()).MetadataReader);
#endif
fieldAccessMetadata.Offset = fieldDesc.Offset;
fieldAccessMetadata.Flags = FieldTableFlags.HasMetadataHandle;
if (fieldDesc.IsThreadStatic)
{
// Specify that the data is thread local
fieldAccessMetadata.Flags |= FieldTableFlags.ThreadStatic;
// Specify that the general purpose field access routine that only relies on offset should be used.
fieldAccessMetadata.Flags |= FieldTableFlags.IsUniversalCanonicalEntry;
}
else if (fieldDesc.IsStatic)
{
uint nonGcStaticsRVA = 0;
uint gcStaticsRVA = 0;
bool nonGenericCase = false;
if (type is MetadataType)
{
// Static fields on Non-Generic types are contained within the module, and their offsets
// are adjusted by their static rva base.
nonGenericCase = true;
#if SUPPORTS_R2R_LOADING
if (!TryGetStaticsTableEntry((MetadataType)type, nonGcStaticsRVA: out nonGcStaticsRVA, gcStaticsRVA: out gcStaticsRVA))
#endif
{
Environment.FailFast(
"Failed to locate statics table entry for for field '" +
fieldName +
"' on type " +
type.ToString());
}
}
if (fieldDesc.HasGCStaticBase)
{
if ((gcStaticsRVA == 0) && nonGenericCase)
{
Environment.FailFast(
"GC statics region was not found for field '" +
fieldName +
"' on type " +
type.ToString());
}
fieldAccessMetadata.Offset += (int)gcStaticsRVA;
fieldAccessMetadata.Flags |= FieldTableFlags.IsGcSection;
}
else
{
if ((nonGcStaticsRVA == 0) && nonGenericCase)
{
Environment.FailFast(
"Non-GC statics region was not found for field '" +
fieldName +
"' on type " +
type.ToString());
}
fieldAccessMetadata.Offset += (int)nonGcStaticsRVA;
}
fieldAccessMetadata.Flags |= FieldTableFlags.Static;
return true;
}
else
{
// Instance field
fieldAccessMetadata.Flags |= FieldTableFlags.Instance;
}
return true;
#else
return false;
#endif
}