本文整理汇总了C#中Internal.TypeSystem.DefType类的典型用法代码示例。如果您正苦于以下问题:C# DefType类的具体用法?C# DefType怎么用?C# DefType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefType类属于Internal.TypeSystem命名空间,在下文中一共展示了DefType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromThreadStaticLayout
/// <summary>
/// Computes the GC pointer map of the thread static region of the type.
/// </summary>
public static GCPointerMap FromThreadStaticLayout(DefType type)
{
GCPointerMapBuilder builder = new GCPointerMapBuilder(type.ThreadStaticFieldSize, type.Context.Target.PointerSize);
foreach (FieldDesc field in type.GetFields())
{
if (!field.IsStatic || field.HasRva || field.IsLiteral || !field.IsThreadStatic)
continue;
TypeDesc fieldType = field.FieldType;
if (fieldType.IsGCPointer)
{
builder.MarkGCPointer(field.Offset);
}
else if (fieldType.IsValueType)
{
var fieldDefType = (DefType)fieldType;
if (fieldDefType.ContainsGCPointers)
{
GCPointerMapBuilder innerBuilder =
builder.GetInnerBuilder(field.Offset, fieldDefType.InstanceByteCount);
FromInstanceLayoutHelper(ref innerBuilder, fieldDefType);
}
}
}
return builder.ToGCMap();
}
示例2: GetRuntimeInterfacesAlgorithmForDefType
protected override RuntimeInterfacesAlgorithm GetRuntimeInterfacesAlgorithmForDefType(DefType type)
{
if (type.RetrieveRuntimeTypeHandleIfPossible() && !type.IsGenericDefinition)
{
// If the type is already constructed, use the NoMetadataRuntimeInterfacesAlgorithm.
// its more efficient than loading from native layout or metadata.
return s_noMetadataRuntimeInterfacesAlgorithm;
}
else if (type.HasNativeLayout)
{
return s_nativeLayoutInterfacesAlgorithm;
}
else if (type is NoMetadataType)
{
return s_noMetadataRuntimeInterfacesAlgorithm;
}
else if (type is MetadataType)
{
return s_metadataRuntimeInterfacesAlgorithm;
}
else
{
Debug.Assert(false);
return null;
}
}
示例3: CanonicallyEquivalentEntryLocator
internal CanonicallyEquivalentEntryLocator(DefType typeToFind, CanonicalFormKind kind)
{
_genericArgs = null;
_genericDefinition = default(RuntimeTypeHandle);
_typeToFind = default(RuntimeTypeHandle);
_canonKind = kind;
_defType = typeToFind;
}
示例4: ComputeInstanceLayout
public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType type, InstanceLayoutKind layoutKind)
{
if (!type.IsTemplateUniversal() && (layoutKind == InstanceLayoutKind.TypeOnly))
{
// Non universal generics can just use the template's layout
DefType template = (DefType)type.ComputeTemplate();
return _noMetadataFieldLayoutAlgorithm.ComputeInstanceLayout(template, InstanceLayoutKind.TypeOnly);
}
// Only needed for universal generics, or when looking up an offset for a field for a universal generic
LowLevelList<int> fieldOffsets;
int[] position = ComputeTypeSizeAndAlignment(type, FieldLoadState.Instance, out fieldOffsets);
int numInstanceFields = 0;
foreach (NativeLayoutFieldDesc field in type.NativeLayoutFields)
{
if (!field.IsStatic)
{
numInstanceFields++;
}
}
int byteCountAlignment = position[InstanceAlignmentEntry];
byteCountAlignment = type.Context.Target.GetObjectAlignment(byteCountAlignment);
ComputedInstanceFieldLayout layout = new ComputedInstanceFieldLayout()
{
Offsets = new FieldAndOffset[numInstanceFields],
ByteCountAlignment = byteCountAlignment,
ByteCountUnaligned = position[(int)NativeFormat.FieldStorage.Instance],
PackValue = 0 // TODO, as we add more metadata handling logic, find out if its necessary to use a meaningful value here
};
if (!type.IsValueType)
{
layout.FieldAlignment = type.Context.Target.PointerSize;
layout.FieldSize = type.Context.Target.PointerSize;
}
else
{
layout.FieldAlignment = position[InstanceAlignmentEntry];
layout.FieldSize = MemoryHelpers.AlignUp(position[(int)NativeFormat.FieldStorage.Instance], layout.FieldAlignment);
}
int curInstanceField = 0;
foreach (NativeLayoutFieldDesc field in type.NativeLayoutFields)
{
if (!field.IsStatic)
{
layout.Offsets[curInstanceField] = new FieldAndOffset(field, fieldOffsets[curInstanceField]);
curInstanceField++;
}
}
return layout;
}
示例5: FromInstanceLayout
/// <summary>
/// Computes the GC pointer map for the instance fields of <paramref name="type"/>.
/// </summary>
public static GCPointerMap FromInstanceLayout(DefType type)
{
Debug.Assert(type.ContainsGCPointers);
GCPointerMapBuilder builder = new GCPointerMapBuilder(type.InstanceByteCount, type.Context.Target.PointerSize);
FromInstanceLayoutHelper(ref builder, type);
return builder.ToGCMap();
}
示例6: InterfaceInSet
/// <summary>
/// Checks if the interface exists in the list of interfaces
/// </summary>
private static bool InterfaceInSet(DefType[] interfaces, int numInterfaces, DefType interfaceType)
{
for (int i = 0; i < numInterfaces; i++)
{
if (interfaces[i].Equals(interfaceType))
return true;
}
return false;
}
示例7: ComputeRuntimeInterfaces
public override DefType[] ComputeRuntimeInterfaces(TypeDesc type)
{
int numInterfaces = RuntimeAugments.GetInterfaceCount(type.RuntimeTypeHandle);
DefType[] interfaces = new DefType[numInterfaces];
for (int i = 0; i < numInterfaces; i++)
{
RuntimeTypeHandle itfHandle = RuntimeAugments.GetInterface(type.RuntimeTypeHandle, i);
TypeDesc itfType = type.Context.ResolveRuntimeTypeHandle(itfHandle);
interfaces[i] = (DefType)itfType;
}
return interfaces;
}
示例8: AppendName
public void AppendName(StringBuilder sb, DefType type)
{
if (!type.IsTypeDefinition)
{
AppendNameForInstantiatedType(sb, type);
}
else
{
DefType containingType = type.ContainingType;
if (containingType != null)
AppendNameForNestedType(sb, type, containingType);
else
AppendNameForNamespaceType(sb, type);
}
}
示例9: BuildPostOrderInterfaceList
/// <summary>
/// Add an interface and its required interfaces to the interfacesArray
/// </summary>
private void BuildPostOrderInterfaceList(DefType iface, ref ArrayBuilder<DefType> interfacesArray)
{
if (interfacesArray.Contains(iface))
return;
foreach (DefType implementedInterface in iface.RuntimeInterfaces)
{
BuildPostOrderInterfaceList(implementedInterface, ref interfacesArray);
}
if (interfacesArray.Contains(iface))
return;
interfacesArray.Add(iface);
}
示例10: ComputeContainsGCPointers
public unsafe override bool ComputeContainsGCPointers(DefType type)
{
if (type.IsTemplateCanonical())
{
return type.ComputeTemplate().RuntimeTypeHandle.ToEETypePtr()->HasGCPointers;
}
else
{
if (type.RetrieveRuntimeTypeHandleIfPossible())
{
return type.RuntimeTypeHandle.ToEETypePtr()->HasGCPointers;
}
return type.GetOrCreateTypeBuilderState().InstanceGCLayout != null;
}
}
示例11: InitializeImplementedInterfaces
private DefType[] InitializeImplementedInterfaces()
{
var interfaceHandles = _typeDefinition.GetInterfaceImplementations();
int count = interfaceHandles.Count;
if (count == 0)
return (_implementedInterfaces = Array.Empty<DefType>());
DefType[] implementedInterfaces = new DefType[count];
int i = 0;
foreach (var interfaceHandle in interfaceHandles)
{
var interfaceImplementation = this.MetadataReader.GetInterfaceImplementation(interfaceHandle);
implementedInterfaces[i++] = (DefType)_module.GetType(interfaceImplementation.Interface);
}
return (_implementedInterfaces = implementedInterfaces);
}
示例12: NoMetadataType
public NoMetadataType(TypeSystemContext context, RuntimeTypeHandle genericTypeDefinition, DefType genericTypeDefinitionAsDefType, Instantiation instantiation, int hashcode)
{
_hashcode = hashcode;
_context = context;
_genericTypeDefinition = genericTypeDefinition;
_genericTypeDefinitionAsDefType = genericTypeDefinitionAsDefType;
if (_genericTypeDefinitionAsDefType == null)
_genericTypeDefinitionAsDefType = this;
_instantiation = instantiation;
// Instantiation must either be:
// Something valid (if the type is generic, or a generic type definition)
// or Empty (if the type isn't a generic of any form)
unsafe
{
Debug.Assert(((_instantiation.Length > 0) && _genericTypeDefinition.ToEETypePtr()->IsGenericTypeDefinition) ||
((_instantiation.Length == 0) && !_genericTypeDefinition.ToEETypePtr()->IsGenericTypeDefinition));
}
}
示例13: InitializeImplementedInterfaces
private DefType[] InitializeImplementedInterfaces()
{
var interfaceHandles = _typeDefinition.Interfaces;
int count = interfaceHandles.Count;
if (count == 0)
return (_implementedInterfaces = Array.Empty<DefType>());
DefType[] implementedInterfaces = new DefType[count];
int i = 0;
foreach (var interfaceHandle in interfaceHandles)
{
implementedInterfaces[i++] = (DefType)_metadataUnit.GetType(interfaceHandle);
}
// TODO Add duplicate detection
return (_implementedInterfaces = implementedInterfaces);
}
示例14: GetLayoutAlgorithmForType
public override FieldLayoutAlgorithm GetLayoutAlgorithmForType(DefType type)
{
if (type.RetrieveRuntimeTypeHandleIfPossible())
{
// If the type is already constructed, use the NoMetadataFieldLayoutAlgorithm.
// its more efficient than loading from native layout or metadata.
return s_noMetadataFieldLayoutAlgorithm;
}
if (type.HasNativeLayout)
{
return s_nativeLayoutFieldAlgorithm;
}
else if (type is NoMetadataType)
{
return s_noMetadataFieldLayoutAlgorithm;
}
else
{
return s_metadataFieldLayoutAlgorithm;
}
}
示例15: InitializeImplementedInterfaces
private DefType[] InitializeImplementedInterfaces()
{
var interfaceHandles = _typeDefinition.GetInterfaceImplementations();
int count = interfaceHandles.Count;
if (count == 0)
return (_implementedInterfaces = Array.Empty<DefType>());
DefType[] implementedInterfaces = new DefType[count];
int i = 0;
foreach (var interfaceHandle in interfaceHandles)
{
var interfaceImplementation = this.MetadataReader.GetInterfaceImplementation(interfaceHandle);
DefType interfaceType = _module.GetType(interfaceImplementation.Interface) as DefType;
if (interfaceType == null)
throw new TypeSystemException.TypeLoadException(ExceptionStringID.ClassLoadBadFormat, this);
implementedInterfaces[i++] = interfaceType;
}
return (_implementedInterfaces = implementedInterfaces);
}