private static bool CheckValueTypeDefaultValueInitializer(EqualsValueClauseSyntax initializer, ITypeSymbol type) { if (!type.IsValueType) { return(false); } switch (type.SpecialType) { case SpecialType.System_Boolean: return(EquivalenceChecker.AreEquivalent(initializer.Value, SyntaxHelper.FalseLiteralExpression)); case SpecialType.System_Decimal: case SpecialType.System_Double: case SpecialType.System_Single: { double constantValue; return(ExpressionNumericConverter.TryGetConstantDoubleValue(initializer.Value, out constantValue) && Math.Abs(constantValue - default(double)) < double.Epsilon); } case SpecialType.System_Char: case SpecialType.System_Byte: case SpecialType.System_Int16: case SpecialType.System_Int32: case SpecialType.System_Int64: case SpecialType.System_SByte: case SpecialType.System_UInt16: case SpecialType.System_UInt32: case SpecialType.System_UInt64: { int constantValue; return(ExpressionNumericConverter.TryGetConstantIntValue(initializer.Value, out constantValue) && constantValue == default(int)); } default: return(false); } }
private static bool CheckValueTypeDefaultValueInitializer(VariableDeclaratorSyntax variable, IFieldSymbol variableSymbol) { if (!variableSymbol.Type.IsValueType) { return(false); } switch (variableSymbol.Type.SpecialType) { case SpecialType.System_Boolean: return(EquivalenceChecker.AreEquivalent(variable.Initializer.Value, FalseExpression)); case SpecialType.System_Decimal: case SpecialType.System_Double: case SpecialType.System_Single: { double constantValue; return(ExpressionNumericConverter.TryGetConstantDoubleValue(variable.Initializer.Value, out constantValue) && Math.Abs(constantValue - default(double)) < double.Epsilon); } case SpecialType.System_Char: case SpecialType.System_Byte: case SpecialType.System_Int16: case SpecialType.System_Int32: case SpecialType.System_Int64: case SpecialType.System_SByte: case SpecialType.System_UInt16: case SpecialType.System_UInt32: case SpecialType.System_UInt64: { int constantValue; return(ExpressionNumericConverter.TryGetConstantIntValue(variable.Initializer.Value, out constantValue) && constantValue == default(int)); } default: return(false); } }