本文整理汇总了C#中TypeSymbol.IsValidSwitchGoverningType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.IsValidSwitchGoverningType方法的具体用法?C# TypeSymbol.IsValidSwitchGoverningType怎么用?C# TypeSymbol.IsValidSwitchGoverningType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.IsValidSwitchGoverningType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassifyImplicitUserDefinedConversionForSwitchGoverningType
internal Conversion ClassifyImplicitUserDefinedConversionForSwitchGoverningType(TypeSymbol sourceType, out TypeSymbol switchGoverningType, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
// SPEC: The governing type of a switch statement is established by the switch expression.
// SPEC: 1) If the type of the switch expression is sbyte, byte, short, ushort, int, uint,
// SPEC: long, ulong, bool, char, string, or an enum-type, or if it is the nullable type
// SPEC: corresponding to one of these types, then that is the governing type of the switch statement.
// SPEC: 2) Otherwise, exactly one user-defined implicit conversion (§6.4) must exist from the
// SPEC: type of the switch expression to one of the following possible governing types:
// SPEC: sbyte, byte, short, ushort, int, uint, long, ulong, char, string, or, a nullable type
// SPEC: corresponding to one of those types
// NOTE: We should be called only if (1) is false for source type.
Debug.Assert((object)sourceType != null);
Debug.Assert(!sourceType.IsValidSwitchGoverningType());
UserDefinedConversionResult result = AnalyzeImplicitUserDefinedConversionForSwitchGoverningType(sourceType, ref useSiteDiagnostics);
if (result.Kind == UserDefinedConversionResultKind.Valid)
{
UserDefinedConversionAnalysis analysis = result.Results[result.Best];
switchGoverningType = analysis.ToType;
Debug.Assert(switchGoverningType.IsValidSwitchGoverningType(isTargetTypeOfUserDefinedOp: true));
}
else
{
switchGoverningType = null;
}
return new Conversion(result, isImplicit: true);
}