本文整理汇总了C#中ConversionsBase.HasIdentityOrImplicitReferenceConversion方法的典型用法代码示例。如果您正苦于以下问题:C# ConversionsBase.HasIdentityOrImplicitReferenceConversion方法的具体用法?C# ConversionsBase.HasIdentityOrImplicitReferenceConversion怎么用?C# ConversionsBase.HasIdentityOrImplicitReferenceConversion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConversionsBase
的用法示例。
在下文中一共展示了ConversionsBase.HasIdentityOrImplicitReferenceConversion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: IsEncompassedBy
/// <summary>
/// Returns true if type a is encompassed by type b (spec 6.4.3),
/// and returns false otherwise.
/// </summary>
private static bool IsEncompassedBy(ConversionsBase conversions, TypeSymbol a, TypeSymbol b, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert(IsValidEncompassedByArgument(a));
Debug.Assert(IsValidEncompassedByArgument(b));
return conversions.HasIdentityOrImplicitReferenceConversion(a, b, ref useSiteDiagnostics) || conversions.HasBoxingConversion(a, b, ref useSiteDiagnostics);
}
示例3: CheckEffectiveAndDeducedBaseTypes
private static void CheckEffectiveAndDeducedBaseTypes(ConversionsBase conversions, TypeSymbol effectiveBase, TypeSymbol deducedBase)
{
Debug.Assert((object)deducedBase != null);
Debug.Assert((object)effectiveBase != null);
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
Debug.Assert(deducedBase.IsErrorType() ||
effectiveBase.IsErrorType() ||
conversions.HasIdentityOrImplicitReferenceConversion(deducedBase, effectiveBase, ref useSiteDiagnostics) ||
conversions.HasBoxingConversion(deducedBase, effectiveBase, ref useSiteDiagnostics));
}