当前位置: 首页>>代码示例>>C#>>正文


C# TypeDesc.IsWellKnownType方法代码示例

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


在下文中一共展示了TypeDesc.IsWellKnownType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanCastGenericParameterTo

        private static bool CanCastGenericParameterTo(this GenericParameterDesc thisType, TypeDesc otherType, StackOverflowProtect protect)
        {
            // A boxed variable type can be cast to any of its constraints, or object, if none are specified
            if (otherType.IsObject)
            {
                return true;
            }

            if (thisType.HasNotNullableValueTypeConstraint &&
                otherType.IsWellKnownType(WellKnownType.ValueType))
            {
                return true;
            }

            foreach (var typeConstraint in thisType.TypeConstraints)
            {
                if (typeConstraint.CanCastToInternal(otherType, protect))
                {
                    return true;
                }
            }

            return false;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:24,代码来源:CastingHelper.cs

示例2: ComputeFlags

        public static UInt16 ComputeFlags(TypeDesc type)
        {
            UInt16 flags = (UInt16)EETypeKind.CanonicalEEType;

            if (type.IsInterface)
            {
                flags |= (UInt16)EETypeFlags.IsInterfaceFlag;
            }

            if (type.IsValueType)
            {
                flags |= (UInt16)EETypeFlags.ValueTypeFlag;
            }

            if (type.IsGenericDefinition)
            {
                flags |= (UInt16)EETypeKind.GenericTypeDefEEType;

                // Generic type definition EETypes don't set the other flags.
                return flags;
            }

            if (type.IsArray || type.IsPointer)
            {
                flags = (UInt16)EETypeKind.ParameterizedEEType;
            }

            if (type.HasFinalizer)
            {
                flags |= (UInt16)EETypeFlags.HasFinalizerFlag;
            }

            if (type.IsDefType && ((DefType)type).ContainsGCPointers)
            {
                flags |= (UInt16)EETypeFlags.HasPointersFlag;
            }
            else if (type.IsArray)
            {
                var elementType = ((ArrayType)type).ElementType;
                if ((elementType.IsValueType && ((DefType)elementType).ContainsGCPointers) || elementType.IsGCPointer)
                {
                    flags |= (UInt16)EETypeFlags.HasPointersFlag;
                }
            }

            if (type.HasInstantiation)
            {
                flags |= (UInt16)EETypeFlags.IsGenericFlag;

                if (type.HasVariance)
                {
                    flags |= (UInt16)EETypeFlags.GenericVarianceFlag;
                }
            }

            CorElementType corElementType = CorElementType.ELEMENT_TYPE_END;

            // The top 5 bits of flags are used to convey enum underlying type, primitive type, or mark the type as being System.Array
            if (type.IsEnum)
            {
                TypeDesc underlyingType = type.UnderlyingType;
                Debug.Assert(TypeFlags.SByte <= underlyingType.Category && underlyingType.Category <= TypeFlags.UInt64);
                corElementType = ComputeRhCorElementType(underlyingType);
            }
            else if (type.IsPrimitive)
            {
                corElementType = ComputeRhCorElementType(type);
            }
            else if (type.IsWellKnownType(WellKnownType.Array))
            {
                // Mark System.Array with CorElementType so casting code can distinguish it
                corElementType = CorElementType.ELEMENT_TYPE_ARRAY;
            }

            if (corElementType != CorElementType.ELEMENT_TYPE_END)
            {
                flags |= (UInt16)((UInt16)corElementType << (UInt16)EETypeFlags.CorElementTypeShift);
            }

            return flags;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:81,代码来源:EETypeBuilderHelpers.cs


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