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


C# TypeInfo.IsNullable方法代码示例

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


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

示例1: SupportsType

        public Boolean SupportsType(TypeInfo typeInfo)
        {
            if (typeInfo == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(typeInfo));
            }

            return typeInfo.IsNullable();
        }
开发者ID:NaseUkolyCZ,项目名称:HarshPoint,代码行数:9,代码来源:NullDefaultValuePolicy.cs

示例2: AreTypesAssignable

        //
        // Determines if a value of the source type can be assigned to a location of the target type.
        // It does not handle ICastable, and cannot since we do not have an actual object instance here.
        // This routine assumes that the source type is boxed, i.e. a value type source is presumed to be
        // compatible with Object and ValueType and an enum source is additionally compatible with Enum.
        //
        private static bool AreTypesAssignable(TypeInfo pSourceType, TypeInfo pTargetType)
        {
            // Special case: T can be cast to Nullable<T> (where T is a value type). Call this case out here
            // since this is only applicable if T is boxed, which is not true for any other callers of
            // AreTypesAssignableInternal, so no sense making all the other paths pay the cost of the check.
            if (pTargetType.IsNullable() && pSourceType.IsValueType && !pSourceType.IsNullable())
            {
                Type pNullableType = pTargetType.GetNullableType();

                return AreTypesEquivalentInternal(pSourceType, pNullableType.GetTypeInfo());
            }

            return AreTypesAssignableInternal(pSourceType, pTargetType, true, false);
        }
开发者ID:tijoytom,项目名称:corert,代码行数:20,代码来源:TypeCast.cs

示例3: SatisfiesConstraints

        static bool SatisfiesConstraints(this TypeInfo genericVariable, SigTypeContext typeContextOfConstraintDeclarer, TypeInfo typeArg)
        {
            GenericParameterAttributes specialConstraints = genericVariable.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;

            if ((specialConstraints & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
            {
                if (!typeArg.IsValueType)
                    return false;
                else
                {
                    // the type argument is a value type, however if it is any kind of Nullable we want to fail
                    // as the constraint accepts any value type except Nullable types (Nullable itself is a value type)
                    if (typeArg.IsNullable())
                        return false;
                }
            }

            if ((specialConstraints & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
            {
                if (typeArg.IsValueType)
                    return false;
            }

            if ((specialConstraints & GenericParameterAttributes.DefaultConstructorConstraint) != 0)
            {
                if (!typeArg.HasExplicitOrImplicitPublicDefaultConstructor())
                    return false;
            }

            // Now check general subtype constraints
            foreach (var constraint in genericVariable.GetGenericParameterConstraints())
            {
                TypeInfo typeConstraint = constraint.GetTypeInfo();

                TypeInfo instantiatedTypeConstraint = typeConstraint.Instantiate(typeContextOfConstraintDeclarer);

                // System.Object constraint will be always satisfied - even if argList is empty
                if (instantiatedTypeConstraint.IsSystemObject())
                    continue;

                // if a concrete type can be cast to the constraint, then this constraint will be satisifed
                if (!AreTypesAssignable(typeArg, instantiatedTypeConstraint))
                    return false;
            }

            return true;
        }
开发者ID:noahfalk,项目名称:corert,代码行数:47,代码来源:ConstraintValidator.cs

示例4: SupportsType

        public Boolean SupportsType(TypeInfo typeInfo)
        {
            if (typeInfo == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(typeInfo));
            }

            if (typeInfo.IsNullable())
            {
                return true;
            }

            if (GuidTypeInfo.Equals(typeInfo))
            {
                return true;
            }

            if (IEnumerableTypeInfo.IsAssignableFrom(typeInfo))
            {
                return true;
            }

            return false;
        }
开发者ID:NaseUkolyCZ,项目名称:HarshPoint,代码行数:24,代码来源:ProvisioningDefaultValuePolicy.cs


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