本文整理汇总了C#中TypeSymbol.ContainsDynamic方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.ContainsDynamic方法的具体用法?C# TypeSymbol.ContainsDynamic怎么用?C# TypeSymbol.ContainsDynamic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.ContainsDynamic方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsValidConstraintType
/// <summary>
/// Returns true if the type is a valid constraint type.
/// Otherwise returns false and generates a diagnostic.
/// </summary>
private static bool IsValidConstraintType(TypeConstraintSyntax syntax, TypeSymbol type, DiagnosticBag diagnostics)
{
switch (type.SpecialType)
{
case SpecialType.System_Object:
case SpecialType.System_ValueType:
case SpecialType.System_Enum:
case SpecialType.System_Delegate:
case SpecialType.System_MulticastDelegate:
case SpecialType.System_Array:
// "Constraint cannot be special class '{0}'"
Error(diagnostics, ErrorCode.ERR_SpecialTypeAsBound, syntax, type);
return false;
}
switch (type.TypeKind)
{
case TypeKind.Error:
case TypeKind.TypeParameter:
return true;
case TypeKind.Interface:
break;
case TypeKind.DynamicType:
// "Constraint cannot be the dynamic type"
Error(diagnostics, ErrorCode.ERR_DynamicTypeAsBound, syntax);
return false;
case TypeKind.Class:
if (type.IsSealed)
{
goto case TypeKind.Struct;
}
else if (type.IsStatic)
{
// "'{0}': static classes cannot be used as constraints"
Error(diagnostics, ErrorCode.ERR_ConstraintIsStaticClass, syntax, type);
return false;
}
break;
case TypeKind.Delegate:
case TypeKind.Enum:
case TypeKind.Struct:
// "'{0}' is not a valid constraint. A type used as a constraint must be an interface, a non-sealed class or a type parameter."
Error(diagnostics, ErrorCode.ERR_BadBoundType, syntax, type);
return false;
case TypeKind.ArrayType:
case TypeKind.PointerType:
// CS0706 already reported by parser.
return false;
case TypeKind.Submission:
// script class is synthetized, never used as a constraint
default:
Debug.Assert(false, "Unexpected type kind: " + type.TypeKind);
return false;
}
if (type.ContainsDynamic())
{
// "Constraint cannot be a dynamic type '{0}'"
Error(diagnostics, ErrorCode.ERR_ConstructedDynamicTypeAsBound, syntax, type);
return false;
}
return true;
}