本文整理汇总了C#中TypeSymbol.?.IsErrorType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.?.IsErrorType方法的具体用法?C# TypeSymbol.?.IsErrorType怎么用?C# TypeSymbol.?.IsErrorType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.?.IsErrorType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckValidPatternType
private bool CheckValidPatternType(
CSharpSyntaxNode typeSyntax,
BoundExpression operand,
TypeSymbol operandType,
TypeSymbol patternType,
bool patternTypeWasInSource,
bool isVar,
DiagnosticBag diagnostics)
{
if (operandType?.IsErrorType() == true || patternType?.IsErrorType() == true)
{
return false;
}
else if (patternType.IsNullableType() && !isVar && patternTypeWasInSource)
{
// It is an error to use pattern-matching with a nullable type, because you'll never get null. Use the underlying type.
Error(diagnostics, ErrorCode.ERR_PatternNullableType, typeSyntax, patternType, patternType.GetNullableUnderlyingType());
return true;
}
else if (patternType.IsStatic)
{
Error(diagnostics, ErrorCode.ERR_VarDeclIsStaticClass, typeSyntax, patternType);
return true;
}
else if (operand != null && operandType == (object)null && !operand.HasAnyErrors)
{
// It is an error to use pattern-matching with a null, method group, or lambda
Error(diagnostics, ErrorCode.ERR_BadIsPatternExpression, operand.Syntax);
return true;
}
else if (!isVar)
{
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
Conversion conversion =
operand != null
? this.Conversions.ClassifyConversionFromExpression(operand, patternType, ref useSiteDiagnostics, forCast: true)
: this.Conversions.ClassifyConversionFromType(operandType, patternType, ref useSiteDiagnostics, forCast: true);
diagnostics.Add(typeSyntax, useSiteDiagnostics);
switch (conversion.Kind)
{
case ConversionKind.Boxing:
case ConversionKind.ExplicitNullable:
case ConversionKind.ExplicitReference:
case ConversionKind.Identity:
case ConversionKind.ImplicitReference:
case ConversionKind.Unboxing:
case ConversionKind.NullLiteral:
case ConversionKind.ImplicitNullable:
// these are the conversions allowed by a pattern match
break;
//case ConversionKind.ExplicitNumeric: // we do not perform numeric conversions of the operand
//case ConversionKind.ImplicitConstant:
//case ConversionKind.ImplicitNumeric:
default:
Error(diagnostics, ErrorCode.ERR_PatternWrongType, typeSyntax, operandType, patternType);
return true;
}
}
return false;
}