本文整理汇总了C#中Internal.TypeSystem.TypeDesc.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc.ToString方法的具体用法?C# TypeDesc.ToString怎么用?C# TypeDesc.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal.TypeSystem.TypeDesc
的用法示例。
在下文中一共展示了TypeDesc.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetMetadataNativeLayout
/// <summary>
/// Get the NativeLayout for a type from a ReadyToRun image.
/// </summary>
public bool TryGetMetadataNativeLayout(TypeDesc concreteType, out IntPtr nativeLayoutInfoModule, out uint nativeLayoutInfoToken)
{
nativeLayoutInfoModule = default(IntPtr);
nativeLayoutInfoToken = 0;
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
var nativeMetadataType = concreteType.GetTypeDefinition() as TypeSystem.NativeFormat.NativeFormatType;
if (nativeMetadataType == null)
return false;
var canonForm = concreteType.ConvertToCanonForm(CanonicalFormKind.Specific);
var hashCode = canonForm.GetHashCode();
var loadedModulesCount = RuntimeAugments.GetLoadedModules(null);
var loadedModuleHandles = new IntPtr[loadedModulesCount];
var loadedModules = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
Debug.Assert(loadedModulesCount == loadedModules);
#if SUPPORTS_R2R_LOADING
foreach (var moduleHandle in loadedModuleHandles)
{
ExternalReferencesTable externalFixupsTable;
NativeHashtable typeTemplatesHashtable = LoadHashtable(moduleHandle, ReflectionMapBlob.MetadataBasedTypeTemplateMap, out externalFixupsTable);
if (typeTemplatesHashtable.IsNull)
continue;
var enumerator = typeTemplatesHashtable.Lookup(hashCode);
var nativeMetadataUnit = nativeMetadataType.Context.ResolveMetadataUnit(moduleHandle);
NativeParser entryParser;
while (!(entryParser = enumerator.GetNext()).IsNull)
{
var entryTypeHandle = entryParser.GetUnsigned().AsHandle();
TypeDesc typeDesc = nativeMetadataUnit.GetType(entryTypeHandle);
Debug.Assert(typeDesc != null);
if (typeDesc == canonForm)
{
TypeLoaderLogger.WriteLine("Found metadata template for type " + concreteType.ToString() + ": " + typeDesc.ToString());
nativeLayoutInfoToken = (uint)externalFixupsTable.GetRvaFromIndex(entryParser.GetUnsigned());
if (nativeLayoutInfoToken == BadTokenFixupValue)
{
throw new BadImageFormatException();
}
nativeLayoutInfoModule = moduleHandle;
return true;
}
}
}
#endif
#endif
return false;
}
示例2: TryGetTypeTemplate_Internal
private TypeDesc TryGetTypeTemplate_Internal(TypeDesc concreteType, CanonicalFormKind kind, out IntPtr nativeLayoutInfoModule, out uint nativeLayoutInfoToken)
{
nativeLayoutInfoModule = default(IntPtr);
nativeLayoutInfoToken = 0;
var canonForm = concreteType.ConvertToCanonForm(kind);
var hashCode = canonForm.GetHashCode();
var loadedModulesCount = RuntimeAugments.GetLoadedModules(null);
var loadedModuleHandles = new IntPtr[loadedModulesCount];
var loadedModules = RuntimeAugments.GetLoadedModules(loadedModuleHandles);
Debug.Assert(loadedModulesCount == loadedModules);
foreach (var moduleHandle in loadedModuleHandles)
{
ExternalReferencesTable externalFixupsTable;
NativeHashtable typeTemplatesHashtable = LoadHashtable(moduleHandle, ReflectionMapBlob.TypeTemplateMap, out externalFixupsTable);
if (typeTemplatesHashtable.IsNull)
continue;
var enumerator = typeTemplatesHashtable.Lookup(hashCode);
NativeParser entryParser;
while (!(entryParser = enumerator.GetNext()).IsNull)
{
RuntimeTypeHandle candidateTemplateTypeHandle = externalFixupsTable.GetRuntimeTypeHandleFromIndex(entryParser.GetUnsigned());
TypeDesc candidateTemplate = concreteType.Context.ResolveRuntimeTypeHandle(candidateTemplateTypeHandle);
if (canonForm == candidateTemplate.ConvertToCanonForm(kind))
{
TypeLoaderLogger.WriteLine("Found template for type " + concreteType.ToString() + ": " + candidateTemplate.ToString());
nativeLayoutInfoToken = (uint)externalFixupsTable.GetRvaFromIndex(entryParser.GetUnsigned());
if (nativeLayoutInfoToken == BadTokenFixupValue)
{
// TODO: once multifile gets fixed up, make this throw a BadImageFormatException
TypeLoaderLogger.WriteLine("ERROR: template not fixed up, skipping");
continue;
}
Debug.Assert(
(kind != CanonicalFormKind.Universal && candidateTemplate != candidateTemplate.ConvertToCanonForm(kind)) ||
(kind == CanonicalFormKind.Universal && candidateTemplate == candidateTemplate.ConvertToCanonForm(kind)));
nativeLayoutInfoModule = moduleHandle;
return candidateTemplate;
}
}
}
TypeLoaderLogger.WriteLine("ERROR: Cannot find a suitable template for type " + concreteType.ToString());
return null;
}
示例3: ComputeTypeSizeAndAlignment
// The layout algorithm should probably compute results and let the caller set things
internal unsafe int[] ComputeTypeSizeAndAlignment(TypeDesc type, FieldLoadState loadRequested, out LowLevelList<int> fieldOffsets)
{
fieldOffsets = null;
TypeLoaderLogger.WriteLine("Laying out type " + type.ToString() + ". IsValueType: " + (type.IsValueType ? "true" : "false") + ". LoadRequested = " + ((int)loadRequested).LowLevelToString());
Debug.Assert(loadRequested != FieldLoadState.None);
Debug.Assert(type is ArrayType || (type is DefType && ((DefType)type).HasInstantiation));
bool isArray = type is ArrayType;
int[] position = new int[5];
int alignRequired = 1;
if ((loadRequested & FieldLoadState.Instance) == FieldLoadState.Instance)
{
ComputeTypeSizeBeforeFields(type, out position[(int)NativeFormat.FieldStorage.Instance], out alignRequired);
}
if (!isArray)
{
// Once this is done, the NativeLayoutFields on the type are initialized
EnsureFieldLayoutLoadedForGenericType((DefType)type);
Debug.Assert(type.NativeLayoutFields != null);
}
int instanceFields = 0;
if (!isArray && type.NativeLayoutFields.Length > 0)
{
fieldOffsets = new LowLevelList<int>(type.NativeLayoutFields.Length);
for (int i = 0; i < type.NativeLayoutFields.Length; i++)
{
TypeDesc fieldType = type.NativeLayoutFields[i].FieldType;
int fieldStorage = (int)type.NativeLayoutFields[i].FieldStorage;
if (!ShouldProcessField((NativeFormat.FieldStorage)fieldStorage, loadRequested))
continue;
// For value types, we will attempt to get the size and alignment from
// the runtime if possible, otherwise GetFieldSizeAndAlignment will
// recurse to lay out nested struct fields.
int alignment;
int size;
GetFieldSizeAlignment(fieldType, out size, out alignment);
Debug.Assert(alignment > 0);
if (fieldStorage == (int)NativeFormat.FieldStorage.Instance)
{
instanceFields++;
// Ensure alignment of type is sufficient for this field
if (alignRequired < alignment)
alignRequired = alignment;
}
position[fieldStorage] = MemoryHelpers.AlignUp(position[fieldStorage], alignment);
TypeLoaderLogger.WriteLine(" --> Field type " + fieldType.ToString() +
" storage " + ((uint)(type.NativeLayoutFields[i].FieldStorage)).LowLevelToString() +
" offset " + position[fieldStorage].LowLevelToString() +
" alignment " + alignment.LowLevelToString());
fieldOffsets.Add(position[fieldStorage]);
position[fieldStorage] += size;
}
}
// Pad the length of structs to be 1 if they are empty so we have no zero-length structures
if ((position[(int)NativeFormat.FieldStorage.Instance] == 0) && type.IsValueType)
position[(int)NativeFormat.FieldStorage.Instance] = 1;
Debug.Assert(alignRequired == 1 || alignRequired == 2 || alignRequired == 4 || alignRequired == 8);
position[InstanceAlignmentEntry] = alignRequired;
return position;
}
示例4: 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
}
示例5: ComputeRuntimeInterfaces
public override DefType[] ComputeRuntimeInterfaces(TypeDesc type)
{
TypeBuilderState state = type.GetOrCreateTypeBuilderState();
int totalInterfaces = RuntimeAugments.GetInterfaceCount(state.TemplateType.RuntimeTypeHandle);
TypeLoaderLogger.WriteLine("Building runtime interfaces for type " + type.ToString() + " (total interfaces = " + totalInterfaces.LowLevelToString() + ") ...");
DefType[] interfaces = new DefType[totalInterfaces];
int numInterfaces = 0;
//
// Copy over all interfaces from base class
//
if (type.BaseType != null)
{
foreach (var baseInterface in type.BaseType.RuntimeInterfaces)
{
// There should be no duplicates
Debug.Assert(!InterfaceInSet(interfaces, numInterfaces, baseInterface));
interfaces[numInterfaces++] = baseInterface;
TypeLoaderLogger.WriteLine(" -> Added basetype interface " + baseInterface.ToString() + " on type " + type.ToString());
}
}
NativeParser typeInfoParser = state.GetParserForNativeLayoutInfo();
NativeParser interfaceParser = typeInfoParser.GetParserForBagElementKind(BagElementKind.ImplementedInterfaces);
TypeDesc[] implementedInterfaces;
if (!interfaceParser.IsNull)
implementedInterfaces = state.NativeLayoutInfo.LoadContext.GetTypeSequence(ref interfaceParser);
else
implementedInterfaces = TypeDesc.EmptyTypes;
// Note that the order in which the interfaces are added to the list is same as the order in which the MDIL binder adds them.
// It is required for correctness
foreach (TypeDesc interfaceType in implementedInterfaces)
{
DefType interfaceTypeAsDefType = (DefType)interfaceType;
// Skip duplicates
if (InterfaceInSet(interfaces, numInterfaces, interfaceTypeAsDefType))
continue;
interfaces[numInterfaces++] = interfaceTypeAsDefType;
TypeLoaderLogger.WriteLine(" -> Added interface " + interfaceTypeAsDefType.ToString() + " on type " + type.ToString());
foreach (var inheritedInterface in interfaceTypeAsDefType.RuntimeInterfaces)
{
// Skip duplicates
if (InterfaceInSet(interfaces, numInterfaces, inheritedInterface))
continue;
interfaces[numInterfaces++] = inheritedInterface;
TypeLoaderLogger.WriteLine(" -> Added inherited interface " + inheritedInterface.ToString() + " on type " + type.ToString());
}
}
// TODO: Handle the screwy cases of generic interface folding
Debug.Assert(numInterfaces == totalInterfaces, "Unexpected number of interfaces");
return interfaces;
}