protected override SyntaxNode CreateExplicitlyCastedLiteralValue( INamedTypeSymbol enumType, SpecialType underlyingSpecialType, object constantValue) { var expression = ExpressionGenerator.GenerateNonEnumValueExpression( enumType.EnumUnderlyingType, constantValue, canUseFieldReference: true); var constantValueULong = EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(constantValue, underlyingSpecialType); if (constantValueULong == 0) { // 0 is always convertible to an enum type without needing a cast. return expression; } var factory = new CSharpSyntaxFactory(); return factory.CreateCastExpression(enumType, expression); }
protected override SyntaxNode CreateExplicitlyCastedLiteralValue( INamedTypeSymbol enumType, SpecialType underlyingSpecialType, object constantValue) { var expression = ExpressionGenerator.GenerateNonEnumValueExpression( enumType.EnumUnderlyingType, constantValue, canUseFieldReference: true); var constantValueULong = EnumUtilities.ConvertEnumUnderlyingTypeToUInt64(constantValue, underlyingSpecialType); if (constantValueULong == 0) { // 0 is always convertible to an enum type without needing a cast. return(expression); } var factory = new CSharpSyntaxFactory(); return(factory.CreateCastExpression(enumType, expression)); }