本文整理汇总了C#中Internal.TypeSystem.TypeDesc类的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc类的具体用法?C# TypeDesc怎么用?C# TypeDesc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeDesc类属于Internal.TypeSystem命名空间,在下文中一共展示了TypeDesc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsBlittableType
/// <summary>
/// Returns true if this is a type that doesn't require marshalling.
/// </summary>
private static bool IsBlittableType(TypeDesc type)
{
type = type.UnderlyingType;
if (type.IsValueType)
{
if (type.IsPrimitive)
{
// All primitive types except char and bool are blittable
TypeFlags category = type.Category;
if (category == TypeFlags.Boolean || category == TypeFlags.Char)
return false;
return true;
}
foreach (FieldDesc field in type.GetFields())
{
if (field.IsStatic)
continue;
TypeDesc fieldType = field.FieldType;
// TODO: we should also reject fields that specify custom marshalling
if (!IsBlittableType(fieldType))
return false;
}
return true;
}
if (type.IsPointer)
return true;
return false;
}
示例2: EETypeNode
public EETypeNode(TypeDesc type)
{
Debug.Assert(!type.IsCanonicalSubtype(CanonicalFormKind.Specific));
Debug.Assert(!type.IsRuntimeDeterminedSubtype);
_type = type;
_optionalFieldsNode = new EETypeOptionalFieldsNode(this);
}
示例3: RootMethods
private void RootMethods(TypeDesc type, string reason, IRootingServiceProvider rootProvider)
{
foreach (MethodDesc method in type.GetMethods())
{
// Skip methods with no IL and uninstantiated generic methods
if (method.IsIntrinsic || method.IsAbstract || method.HasInstantiation)
continue;
if (method.IsInternalCall)
continue;
try
{
CheckCanGenerateMethod(method);
rootProvider.AddCompilationRoot(method, reason);
}
catch (TypeSystemException)
{
// TODO: fail compilation if a switch was passed
// Individual methods can fail to load types referenced in their signatures.
// Skip them in library mode since they're not going to be callable.
continue;
// TODO: Log as a warning
}
}
}
示例4: GetNumberOfBaseSlots
private static int GetNumberOfBaseSlots(NodeFactory factory, TypeDesc owningType)
{
int baseSlots = 0;
TypeDesc baseType = owningType.BaseType;
while (baseType != null)
{
// Normalize the base type. Necessary to make this work with the lazy vtable slot
// concept - if we start with a canonical type, the base type could end up being
// something like Base<__Canon, string>. We would get "0 slots used" for weird
// base types like this.
baseType = baseType.ConvertToCanonForm(CanonicalFormKind.Specific);
// For types that have a generic dictionary, the introduced virtual method slots are
// prefixed with a pointer to the generic dictionary.
if (baseType.HasGenericDictionarySlot())
baseSlots++;
IReadOnlyList<MethodDesc> baseVirtualSlots = factory.VTable(baseType).Slots;
baseSlots += baseVirtualSlots.Count;
baseType = baseType.BaseType;
}
return baseSlots;
}
示例5: DelegateInfo
public DelegateInfo(TypeDesc delegateType)
{
Debug.Assert(delegateType.IsDelegate);
Debug.Assert(delegateType.IsTypeDefinition);
_delegateType = delegateType;
}
示例6: EmitIL
public static MethodIL EmitIL(MethodDesc target)
{
Debug.Assert(target.Name == "Call");
Debug.Assert(target.Signature.Length > 0
&& target.Signature[0] == target.Context.GetWellKnownType(WellKnownType.IntPtr));
ILEmitter emitter = new ILEmitter();
var codeStream = emitter.NewCodeStream();
// Load all the arguments except the first one (IntPtr address)
for (int i = 1; i < target.Signature.Length; i++)
{
codeStream.EmitLdArg(i);
}
// now load IntPtr address
codeStream.EmitLdArg(0);
// Create a signature for the calli by copying the signature of the containing method
// while skipping the first argument
MethodSignature template = target.Signature;
TypeDesc returnType = template.ReturnType;
TypeDesc[] parameters = new TypeDesc[template.Length - 1];
for (int i = 1; i < template.Length; i++)
{
parameters[i - 1] = template[i];
}
var signature = new MethodSignature(template.Flags, 0, returnType, parameters);
codeStream.Emit(ILOpcode.calli, emitter.NewToken(signature));
codeStream.Emit(ILOpcode.ret);
return emitter.Link();
}
示例7: IsConstructedOverType
/// <summary>
/// Determine if the construction of a type contains one of a given set of types. This is a deep
/// scan. For instance, given type MyType<SomeGeneric<int[]>>, and a set of typesToFind
/// that includes int, this function will return true. Does not detect the open generics that may be
/// instantiated over in this type. IsConstructedOverType would return false if only passed MyType,
/// or SomeGeneric for the above examplt.
/// </summary>
/// <param name="type">type to examine</param>
/// <param name="typesToFind">types to search for in the construction of type</param>
/// <returns>true if a type in typesToFind is found</returns>
public static bool IsConstructedOverType(this TypeDesc type, TypeDesc[] typesToFind)
{
int directDiscoveryIndex = Array.IndexOf(typesToFind, type);
if (directDiscoveryIndex != -1)
return true;
if (type.HasInstantiation)
{
for (int instantiationIndex = 0; instantiationIndex < type.Instantiation.Length; instantiationIndex++)
{
if (type.Instantiation[instantiationIndex].IsConstructedOverType(typesToFind))
{
return true;
}
}
}
else if (type.IsParameterizedType)
{
ParameterizedType parameterizedType = (ParameterizedType)type;
return parameterizedType.ParameterType.IsConstructedOverType(typesToFind);
}
return false;
}
示例8: ExternEETypeSymbolNode
public ExternEETypeSymbolNode(NodeFactory factory, TypeDesc type)
: base("__EEType_" + NodeFactory.NameMangler.GetMangledTypeName(type))
{
_type = type;
EETypeNode.CheckCanGenerateEEType(factory, type);
}
示例9: GetRuntimeTypeHandleWithNullableTransform
// Helper method for nullable transform. Ideally, we would do the nullable transform upfront before
// the types is build. Unfortunately, there does not seem to be easy way to test for Nullable<> type definition
// without introducing type builder recursion
private static RuntimeTypeHandle GetRuntimeTypeHandleWithNullableTransform(TypeBuilder builder, TypeDesc type)
{
RuntimeTypeHandle th = builder.GetRuntimeTypeHandle(type);
if (RuntimeAugments.IsNullable(th))
th = builder.GetRuntimeTypeHandle(((DefType)type).Instantiation[0]);
return th;
}
示例10: ConvertInstantiationToCanonForm
/// <summary>
/// Returns a new instantiation that canonicalizes all types in <paramref name="instantiation"/>
/// if possible under the policy of '<paramref name="kind"/>'
/// </summary>
/// <param name="changed">True if the returned instantiation is different from '<paramref name="instantiation"/>'.</param>
public static Instantiation ConvertInstantiationToCanonForm(Instantiation instantiation, CanonicalFormKind kind, out bool changed)
{
TypeDesc[] newInstantiation = null;
for (int i = 0; i < instantiation.Length; i++)
{
TypeDesc typeToConvert = instantiation[i];
TypeDesc convertedType = ConvertToCanon(typeToConvert, kind);
if (typeToConvert != convertedType || newInstantiation != null)
{
if (newInstantiation == null)
{
newInstantiation = new TypeDesc[instantiation.Length];
for (int j = 0; j < i; j++)
newInstantiation[j] = instantiation[j];
}
newInstantiation[i] = convertedType;
}
}
changed = newInstantiation != null;
if (changed)
{
return new Instantiation(newInstantiation);
}
return instantiation;
}
示例11: FixupCellMetadataResolver
public FixupCellMetadataResolver(NativeFormatMetadataUnit metadataUnit, TypeDesc typeContext)
{
_metadataUnit = metadataUnit;
_typeContext = typeContext;
_methodContext = null;
_loadContextFromNativeLayout = null;
}
示例12: 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));
}
}
示例13: IsSimpleType
/// <summary>
/// Returns true if <paramref name="type"/> doesn't require marshalling and can be directly passed
/// to native code.
/// </summary>
private static bool IsSimpleType(TypeDesc type)
{
type = type.UnderlyingType;
switch (type.Category)
{
case TypeFlags.Byte:
case TypeFlags.SByte:
case TypeFlags.UInt16:
case TypeFlags.Int16:
case TypeFlags.UInt32:
case TypeFlags.Int32:
case TypeFlags.UInt64:
case TypeFlags.Int64:
case TypeFlags.Double:
case TypeFlags.Single:
case TypeFlags.UIntPtr:
case TypeFlags.IntPtr:
return true;
}
if (type.IsPointer)
return true;
return false;
}
示例14: AppendName
public void AppendName(StringBuilder sb, TypeDesc type)
{
switch (type.Category)
{
case TypeFlags.Array:
case TypeFlags.SzArray:
AppendName(sb, (ArrayType)type);
return;
case TypeFlags.ByRef:
AppendName(sb, (ByRefType)type);
return;
case TypeFlags.Pointer:
AppendName(sb, (PointerType)type);
return;
case TypeFlags.GenericParameter:
AppendName(sb, (GenericParameterDesc)type);
return;
case TypeFlags.SignatureTypeVariable:
AppendName(sb, (SignatureTypeVariable)type);
return;
case TypeFlags.SignatureMethodVariable:
AppendName(sb, (SignatureMethodVariable)type);
return;
default:
Debug.Assert(type.IsDefType);
AppendName(sb, (DefType)type);
return;
}
}
示例15: ConvertInstantiationToSharedRuntimeForm
public static Instantiation ConvertInstantiationToSharedRuntimeForm(Instantiation instantiation, Instantiation openInstantiation, out bool changed)
{
Debug.Assert(instantiation.Length == openInstantiation.Length);
TypeDesc[] sharedInstantiation = null;
CanonicalFormKind currentPolicy = CanonicalFormKind.Specific;
CanonicalFormKind startLoopPolicy;
do
{
startLoopPolicy = currentPolicy;
for (int instantiationIndex = 0; instantiationIndex < instantiation.Length; instantiationIndex++)
{
TypeDesc typeToConvert = instantiation[instantiationIndex];
TypeSystemContext context = typeToConvert.Context;
TypeDesc canonForm = context.ConvertToCanon(typeToConvert, ref currentPolicy);
TypeDesc runtimeDeterminedForm = typeToConvert;
Debug.Assert(openInstantiation[instantiationIndex] is GenericParameterDesc);
if ((typeToConvert != canonForm) || typeToConvert.IsCanonicalType)
{
Debug.Assert(canonForm is DefType);
if (sharedInstantiation == null)
{
sharedInstantiation = new TypeDesc[instantiation.Length];
for (int i = 0; i < instantiationIndex; i++)
sharedInstantiation[i] = instantiation[i];
}
runtimeDeterminedForm = context.GetRuntimeDeterminedType(
(DefType)canonForm, (GenericParameterDesc)openInstantiation[instantiationIndex]);
}
if (sharedInstantiation != null)
{
sharedInstantiation[instantiationIndex] = runtimeDeterminedForm;
}
}
// Optimization: even if canonical policy changed, we don't actually need to re-run the loop
// for instantiations that only have a single element.
if (instantiation.Length == 1)
{
break;
}
} while (currentPolicy != startLoopPolicy);
changed = sharedInstantiation != null;
if (changed)
{
return new Instantiation(sharedInstantiation);
}
return instantiation;
}