• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# TypeSystem.TypeDesc类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Internal.TypeSystem.TypeDesc的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc类的具体用法?C# TypeDesc怎么用?C# TypeDesc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeDesc类属于Internal.TypeSystem命名空间,在下文中一共展示了TypeDesc类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
        }
开发者ID:schellap,项目名称:corert,代码行数:38,代码来源:PInvokeMarshallingILEmitter.cs


示例2: EETypeNode

 public EETypeNode(TypeDesc type)
 {
     Debug.Assert(!type.IsCanonicalSubtype(CanonicalFormKind.Specific));
     Debug.Assert(!type.IsRuntimeDeterminedSubtype);
     _type = type;
     _optionalFieldsNode = new EETypeOptionalFieldsNode(this);
 }
开发者ID:hoyMS,项目名称:corert,代码行数:7,代码来源:EETypeNode.cs


示例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
                }
            }
        }
开发者ID:nattress,项目名称:corert,代码行数:28,代码来源:LibraryRootProvider.cs


示例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;
        }
开发者ID:nattress,项目名称:corert,代码行数:26,代码来源:VirtualMethodCallHelper.cs


示例5: DelegateInfo

        public DelegateInfo(TypeDesc delegateType)
        {
            Debug.Assert(delegateType.IsDelegate);
            Debug.Assert(delegateType.IsTypeDefinition);

            _delegateType = delegateType;
        }
开发者ID:nguerrera,项目名称:corert,代码行数:7,代码来源:DelegateInfo.cs


示例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();
        }
开发者ID:noahfalk,项目名称:corert,代码行数:35,代码来源:CalliIntrinsic.cs


示例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&lt;SomeGeneric&lt;int[]&gt;&gt;, 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;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:35,代码来源:ConstructedTypeRewritingHelpers.cs


示例8: ExternEETypeSymbolNode

        public ExternEETypeSymbolNode(NodeFactory factory, TypeDesc type)
            : base("__EEType_" + NodeFactory.NameMangler.GetMangledTypeName(type))
        {
            _type = type;

            EETypeNode.CheckCanGenerateEEType(factory, type);
        }
开发者ID:nattress,项目名称:corert,代码行数:7,代码来源:ExternEETypeSymbolNode.cs


示例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;
 }
开发者ID:nattress,项目名称:corert,代码行数:10,代码来源:genericdictionarycell.cs


示例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;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:35,代码来源:StandardCanonicalizationAlgorithm.cs


示例11: FixupCellMetadataResolver

 public FixupCellMetadataResolver(NativeFormatMetadataUnit metadataUnit, TypeDesc typeContext)
 {
     _metadataUnit = metadataUnit;
     _typeContext = typeContext;
     _methodContext = null;
     _loadContextFromNativeLayout = null;
 }
开发者ID:nattress,项目名称:corert,代码行数:7,代码来源:FixupCellMetadataResolver.cs


示例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));
            }
        }
开发者ID:nguerrera,项目名称:corert,代码行数:64,代码来源:DelegateCreationInfo.cs


示例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;
        }
开发者ID:niemyjski,项目名称:corert,代码行数:30,代码来源:PInvokeMarshallingILEmitter.cs


示例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;
     }
 }
开发者ID:tijoytom,项目名称:corert,代码行数:29,代码来源:TypeNameFormatter.cs


示例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;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:59,代码来源:RuntimeDeterminedTypeUtilities.cs


示例16: ComputeRuntimeInterfaces

        public override DefType[] ComputeRuntimeInterfaces(TypeDesc _type)
        {
            ArrayType arrayType = (ArrayType)_type;
            Debug.Assert(arrayType.IsSzArray);
            TypeDesc arrayOfTInstantiation = _arrayOfTType.MakeInstantiatedType(arrayType.ElementType);

            return arrayOfTInstantiation.RuntimeInterfaces;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:8,代码来源:ArrayOfTRuntimeInterfacesAlgorithm.cs


示例17: ComputeAllVirtualMethods

 public override IEnumerable<MethodDesc> ComputeAllVirtualMethods(TypeDesc type)
 {
     foreach (var method in type.GetMethods())
     {
         if (method.IsVirtual)
             yield return method;
     }
 }
开发者ID:tijoytom,项目名称:corert,代码行数:8,代码来源:MetadataVirtualMethodEnumerationAlgorithm.cs


示例18: ComputeHasStaticConstructor

 protected sealed internal override bool ComputeHasStaticConstructor(TypeDesc type)
 {
     if (type is MetadataType)
     {
         return ((MetadataType)type).GetStaticConstructor() != null;
     }
     return false;
 }
开发者ID:hoyMS,项目名称:corert,代码行数:8,代码来源:MetadataTypeSystemContext.cs


示例19: AppendOwningType

 private void AppendOwningType(StringBuilder sb, TypeDesc type)
 {
     // Special case primitive types: we don't want to use short names here
     if (type.IsPrimitive || type.IsString || type.IsObject)
         _typeNameFormatter.AppendNameForNamespaceTypeWithoutAliases(sb, (MetadataType)type);
     else
         AppendType(sb, type, false);
 }
开发者ID:tijoytom,项目名称:corert,代码行数:8,代码来源:ILDisassember.cs


示例20: GetMangledTypeName

        public string GetMangledTypeName(TypeDesc type)
        {
            string mangledName;
            if (_mangledTypeNames.TryGetValue(type, out mangledName))
                return mangledName;

            return ComputeMangledTypeName(type);
        }
开发者ID:noahfalk,项目名称:corert,代码行数:8,代码来源:NameMangler.cs



注:本文中的Internal.TypeSystem.TypeDesc类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Compiler.TokenStream类代码示例发布时间:2022-05-26
下一篇:
C# TypeSystem.MethodSignature类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap