本文整理汇总了C#中ConversionsBase.HasImplicitTypeParameterConversion方法的典型用法代码示例。如果您正苦于以下问题:C# ConversionsBase.HasImplicitTypeParameterConversion方法的具体用法?C# ConversionsBase.HasImplicitTypeParameterConversion怎么用?C# ConversionsBase.HasImplicitTypeParameterConversion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConversionsBase
的用法示例。
在下文中一共展示了ConversionsBase.HasImplicitTypeParameterConversion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SatisfiesConstraintType
private static bool SatisfiesConstraintType(
ConversionsBase conversions,
TypeSymbol typeArgument,
TypeSymbol constraintType,
ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
if (constraintType.IsErrorType())
{
return false;
}
// Spec 4.4.4 describes the valid conversions from
// type argument A to constraint type C:
// "An identity conversion (6.1.1).
// An implicit reference conversion (6.1.6). ..."
if (conversions.HasIdentityOrImplicitReferenceConversion(typeArgument, constraintType, ref useSiteDiagnostics))
{
return true;
}
// "... A boxing conversion (6.1.7), provided that type A is a non-nullable value type. ..."
// NOTE: we extend this to allow, for example, a conversion from Nullable<T> to object.
if (typeArgument.IsValueType &&
conversions.HasBoxingConversion(typeArgument.IsNullableType() ? ((NamedTypeSymbol)typeArgument).ConstructedFrom : typeArgument, constraintType, ref useSiteDiagnostics))
{
return true;
}
if (typeArgument.TypeKind == TypeKind.TypeParameter)
{
var typeParameter = (TypeParameterSymbol)typeArgument;
// "... An implicit reference, boxing, or type parameter conversion
// from type parameter A to C."
if (conversions.HasImplicitTypeParameterConversion(typeParameter, constraintType, ref useSiteDiagnostics))
{
return true;
}
// TypeBind::SatisfiesBound allows cases where one of the
// type parameter constraints satisfies the constraint.
foreach (var typeArgumentConstraint in typeParameter.ConstraintTypesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics))
{
if (SatisfiesConstraintType(conversions, typeArgumentConstraint, constraintType, ref useSiteDiagnostics))
{
return true;
}
}
}
return false;
}