本文整理汇总了C#中Internal.TypeSystem.TypeDesc.GetTypeDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc.GetTypeDefinition方法的具体用法?C# TypeDesc.GetTypeDefinition怎么用?C# TypeDesc.GetTypeDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Internal.TypeSystem.TypeDesc
的用法示例。
在下文中一共展示了TypeDesc.GetTypeDefinition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Constructs a new instance of <see cref="DelegateCreationInfo"/> set up to construct a delegate of type
/// '<paramref name="delegateType"/>' pointing to '<paramref name="targetMethod"/>'.
/// </summary>
public static DelegateCreationInfo Create(TypeDesc delegateType, MethodDesc targetMethod, NodeFactory factory)
{
var context = (CompilerTypeSystemContext)delegateType.Context;
var systemDelegate = targetMethod.Context.GetWellKnownType(WellKnownType.MulticastDelegate).BaseType;
int paramCountTargetMethod = targetMethod.Signature.Length;
if (!targetMethod.Signature.IsStatic)
{
paramCountTargetMethod++;
}
DelegateInfo delegateInfo = context.GetDelegateInfo(delegateType.GetTypeDefinition());
int paramCountDelegateClosed = delegateInfo.Signature.Length + 1;
bool closed = false;
if (paramCountDelegateClosed == paramCountTargetMethod)
{
closed = true;
}
else
{
Debug.Assert(paramCountDelegateClosed == paramCountTargetMethod + 1);
}
if (targetMethod.Signature.IsStatic)
{
MethodDesc invokeThunk;
if (!closed)
{
// Open delegate to a static method
invokeThunk = delegateInfo.Thunks[DelegateThunkKind.OpenStaticThunk];
}
else
{
// Closed delegate to a static method (i.e. delegate to an extension method that locks the first parameter)
invokeThunk = delegateInfo.Thunks[DelegateThunkKind.ClosedStaticThunk];
}
var instantiatedDelegateType = delegateType as InstantiatedType;
if (instantiatedDelegateType != null)
invokeThunk = context.GetMethodForInstantiatedType(invokeThunk, instantiatedDelegateType);
// We use InitializeClosedStaticThunk for both because RyuJIT generates same code for both,
// but passes null as the first parameter for the open one.
return new DelegateCreationInfo(
factory.MethodEntrypoint(systemDelegate.GetKnownMethod("InitializeClosedStaticThunk", null)),
factory.MethodEntrypoint(targetMethod),
factory.MethodEntrypoint(invokeThunk));
}
else
{
if (!closed)
throw new NotImplementedException("Open instance delegates");
bool useUnboxingStub = targetMethod.OwningType.IsValueType;
return new DelegateCreationInfo(
factory.MethodEntrypoint(systemDelegate.GetKnownMethod("InitializeClosedInstance", null)),
factory.MethodEntrypoint(targetMethod, useUnboxingStub));
}
}
示例2: 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;
}
示例3: ComputeAllVirtualMethods
public override IEnumerable<MethodDesc> ComputeAllVirtualMethods(TypeDesc type)
{
var context = (CompilerTypeSystemContext)type.Context;
InstantiatedType instantiatedType = type as InstantiatedType;
if (instantiatedType != null)
{
DelegateInfo info = context.GetDelegateInfo(type.GetTypeDefinition());
yield return context.GetMethodForInstantiatedType(info.GetThunkMethod, instantiatedType);
}
else
{
DelegateInfo info = context.GetDelegateInfo(type);
yield return info.GetThunkMethod;
}
}
示例4: ComputeMangledTypeName
/// <summary>
/// If given <param name="type"/> is an <see cref="EcmaType"/> precompute its mangled type name
/// along with all the other types from the same module as <param name="type"/>.
/// Otherwise, it is a constructed type and to the EcmaType's mangled name we add a suffix to
/// show what kind of constructed type it is (e.g. appending __Array for an array type).
/// </summary>
/// <param name="type">Type to mangled</param>
/// <returns>Mangled name for <param name="type"/>.</returns>
private string ComputeMangledTypeName(TypeDesc type)
{
if (type is EcmaType)
{
EcmaType ecmaType = (EcmaType)type;
string prependAssemblyName = SanitizeName(((EcmaAssembly)ecmaType.EcmaModule).GetName().Name);
var deduplicator = new HashSet<string>();
// Add consistent names for all types in the module, independent on the order in which
// they are compiled
lock (this)
{
foreach (MetadataType t in ((EcmaType)type).EcmaModule.GetAllTypes())
{
string name = t.GetFullName();
// Include encapsulating type
DefType containingType = t.ContainingType;
while (containingType != null)
{
name = containingType.GetFullName() + "_" + name;
containingType = containingType.ContainingType;
}
name = SanitizeName(name, true);
if (_mangleForCplusPlus)
{
// Always generate a fully qualified name
name = "::" + prependAssemblyName + "::" + name;
}
else
{
name = prependAssemblyName + "_" + name;
}
// Ensure that name is unique and update our tables accordingly.
name = DisambiguateName(name, deduplicator);
deduplicator.Add(name);
_mangledTypeNames = _mangledTypeNames.Add(t, name);
}
}
return _mangledTypeNames[type];
}
string mangledName;
switch (type.Category)
{
case TypeFlags.Array:
case TypeFlags.SzArray:
// mangledName = "Array<" + GetSignatureCPPTypeName(((ArrayType)type).ElementType) + ">";
mangledName = GetMangledTypeName(((ArrayType)type).ElementType) + "__Array";
if (!type.IsSzArray)
mangledName += "Rank" + ((ArrayType)type).Rank.ToStringInvariant();
break;
case TypeFlags.ByRef:
mangledName = GetMangledTypeName(((ByRefType)type).ParameterType) + "__ByRef";
break;
case TypeFlags.Pointer:
mangledName = GetMangledTypeName(((PointerType)type).ParameterType) + "__Pointer";
break;
default:
// Case of a generic type. If `type' is a type definition we use the type name
// for mangling, otherwise we use the mangling of the type and its generic type
// parameters, e.g. A <B> becomes A__B.
var typeDefinition = type.GetTypeDefinition();
if (typeDefinition != type)
{
mangledName = GetMangledTypeName(typeDefinition);
var inst = type.Instantiation;
for (int i = 0; i < inst.Length; i++)
{
string instArgName = GetMangledTypeName(inst[i]);
if (_mangleForCplusPlus)
instArgName = instArgName.Replace("::", "_");
mangledName += "__" + instArgName;
}
}
else
{
mangledName = SanitizeName(((DefType)type).GetFullName(), true);
}
break;
}
lock (this)
//.........这里部分代码省略.........
示例5: HasSameTypeDefinition
/// <summary>
/// Determine if two types share the same type definition
/// </summary>
public bool HasSameTypeDefinition(TypeDesc otherType)
{
return GetTypeDefinition() == otherType.GetTypeDefinition();
}
示例6: ComputeMangledTypeName
private string ComputeMangledTypeName(TypeDesc type)
{
if (type is EcmaType)
{
string prependAssemblyName = SanitizeName(((EcmaType)type).EcmaModule.GetName().Name);
var deduplicator = new HashSet<string>();
// Add consistent names for all types in the module, independent on the order in which
// they are compiled
lock (this)
{
foreach (MetadataType t in ((EcmaType)type).EcmaModule.GetAllTypes())
{
string name = t.GetFullName();
// Include encapsulating type
MetadataType containingType = t.ContainingType;
while (containingType != null)
{
name = containingType.GetFullName() + "_" + name;
containingType = containingType.ContainingType;
}
name = SanitizeName(name, true);
if (deduplicator.Contains(name))
{
string nameWithIndex;
for (int index = 1; ; index++)
{
nameWithIndex = name + "_" + index.ToString(CultureInfo.InvariantCulture);
if (!deduplicator.Contains(nameWithIndex))
break;
}
name = nameWithIndex;
}
deduplicator.Add(name);
if (_compilation.IsCppCodeGen)
name = prependAssemblyName + "::" + name;
else
name = prependAssemblyName + "_" + name;
_mangledTypeNames = _mangledTypeNames.Add(t, name);
}
}
return _mangledTypeNames[type];
}
string mangledName;
switch (type.Category)
{
case TypeFlags.Array:
// mangledName = "Array<" + GetSignatureCPPTypeName(((ArrayType)type).ElementType) + ">";
mangledName = GetMangledTypeName(((ArrayType)type).ElementType) + "__Array";
if (((ArrayType)type).Rank != 1)
mangledName += "Rank" + ((ArrayType)type).Rank.ToString();
break;
case TypeFlags.ByRef:
mangledName = GetMangledTypeName(((ByRefType)type).ParameterType) + "__ByRef";
break;
case TypeFlags.Pointer:
mangledName = GetMangledTypeName(((PointerType)type).ParameterType) + "__Pointer";
break;
default:
var typeDefinition = type.GetTypeDefinition();
if (typeDefinition != type)
{
mangledName = GetMangledTypeName(typeDefinition);
var inst = type.Instantiation;
for (int i = 0; i < inst.Length; i++)
{
string instArgName = GetMangledTypeName(inst[i]);
if (_compilation.IsCppCodeGen)
instArgName = instArgName.Replace("::", "_");
mangledName += "__" + instArgName;
}
}
else
{
mangledName = SanitizeName(((MetadataType)type).GetFullName(), true);
}
break;
}
lock (this)
{
_mangledTypeNames = _mangledTypeNames.Add(type, mangledName);
}
return mangledName;
}
示例7: 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
}