本文整理汇总了C#中System.Reflection.TypeInfo.IsSzArray方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.IsSzArray方法的具体用法?C# TypeInfo.IsSzArray怎么用?C# TypeInfo.IsSzArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.IsSzArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCastTo
private static bool CanCastTo(this TypeInfo fromTypeInfo, TypeInfo toTypeInfo, FoundationTypes foundationTypes)
{
if (fromTypeInfo.Equals(toTypeInfo))
return true;
if (fromTypeInfo.IsArray)
{
if (toTypeInfo.IsInterface)
return fromTypeInfo.CanCastArrayToInterface(toTypeInfo, foundationTypes);
Type toType = toTypeInfo.AsType();
if (fromTypeInfo.IsSubclassOf(toType))
return true; // T[] is castable to Array or Object.
if (!toTypeInfo.IsArray)
return false;
int rank = fromTypeInfo.GetArrayRank();
if (rank != toTypeInfo.GetArrayRank())
return false;
bool fromTypeIsSzArray = fromTypeInfo.IsSzArray(foundationTypes);
bool toTypeIsSzArray = toTypeInfo.IsSzArray(foundationTypes);
if (fromTypeIsSzArray != toTypeIsSzArray)
{
// T[] is assignable to T[*] but not vice-versa.
if (!(rank == 1 && !toTypeIsSzArray))
{
return false; // T[*] is not castable to T[]
}
}
TypeInfo toElementTypeInfo = toTypeInfo.GetElementType().GetTypeInfo();
TypeInfo fromElementTypeInfo = fromTypeInfo.GetElementType().GetTypeInfo();
return fromElementTypeInfo.IsElementTypeCompatibleWith(toElementTypeInfo, foundationTypes);
}
if (fromTypeInfo.IsByRef)
{
if (!toTypeInfo.IsByRef)
return false;
TypeInfo toElementTypeInfo = toTypeInfo.GetElementType().GetTypeInfo();
TypeInfo fromElementTypeInfo = fromTypeInfo.GetElementType().GetTypeInfo();
return fromElementTypeInfo.IsElementTypeCompatibleWith(toElementTypeInfo, foundationTypes);
}
if (fromTypeInfo.IsPointer)
{
Type toType = toTypeInfo.AsType();
if (toType.Equals(foundationTypes.SystemObject))
return true; // T* is castable to Object.
if (toType.Equals(foundationTypes.SystemUIntPtr))
return true; // T* is castable to UIntPtr (but not IntPtr)
if (!toTypeInfo.IsPointer)
return false;
TypeInfo toElementTypeInfo = toTypeInfo.GetElementType().GetTypeInfo();
TypeInfo fromElementTypeInfo = fromTypeInfo.GetElementType().GetTypeInfo();
return fromElementTypeInfo.IsElementTypeCompatibleWith(toElementTypeInfo, foundationTypes);
}
if (fromTypeInfo.IsGenericParameter)
{
//
// A generic parameter can be cast to any of its constraints, or object, if none are specified, or ValueType if the "struct" constraint is
// specified.
//
// This has to be coded as its own case as TypeInfo.BaseType on a generic parameter doesn't always return what you'd expect.
//
Type toType = toTypeInfo.AsType();
if (toType.Equals(foundationTypes.SystemObject))
return true;
if (toType.Equals(foundationTypes.SystemValueType))
{
GenericParameterAttributes attributes = fromTypeInfo.GenericParameterAttributes;
if ((attributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
return true;
}
foreach (Type constraintType in fromTypeInfo.GetGenericParameterConstraints())
{
if (constraintType.GetTypeInfo().CanCastTo(toTypeInfo, foundationTypes))
return true;
}
return false;
}
if (toTypeInfo.IsArray || toTypeInfo.IsByRef || toTypeInfo.IsPointer || toTypeInfo.IsGenericParameter)
return false;
if (fromTypeInfo.MatchesWithVariance(toTypeInfo, foundationTypes))
return true;
if (toTypeInfo.IsInterface)
{
//.........这里部分代码省略.........