本文整理汇总了C#中System.Reflection.TypeInfo.GetNullableType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.GetNullableType方法的具体用法?C# TypeInfo.GetNullableType怎么用?C# TypeInfo.GetNullableType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.GetNullableType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}