Closed eobeda closed 9 months ago
Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.6.4 AutomaticInterface: 1.6.0
Method with non-null defaults on Boolean parameters throw CS0103 error. Sample method call:
public async Task<Stream?> GetFinalDocumentsByIDFails( string agreementID, string docType, bool amt = false , bool? attachSupportingDocuments = true, CancellationToken cancellationToken = default) { await Task.Delay(100); return default(Stream?); }
Reason: The case of the default value is converted to True or False instead of true or false in the GetMethodSignature method. https://learn.microsoft.com/en-us/dotnet/api/system.boolean?view=net-7.0#converting-to-and-from-boolean-values
Fix: Add an additional case to the swtich statement: bool => $" = {Convert.ToString(x.ExplicitDefaultValue, CultureInfo.InvariantCulture).ToLowerInvariant()}",
AutomaticInterface.cs method "GetMethodSignature" with the fix applied:
private static string GetMethodSignature(IParameterSymbol x) { if (!x.HasExplicitDefaultValue) return $"{x.Type.ToDisplayString()} {x.Name}"; string optionalValue = x.ExplicitDefaultValue switch { string => $" = \"{x.ExplicitDefaultValue}\"", bool => $" = {Convert.ToString(x.ExplicitDefaultValue, CultureInfo.InvariantCulture).ToLowerInvariant()}", // struct null when x.Type.IsValueType => $" = default({x.Type})", null => " = null", _ => $" = {x.ExplicitDefaultValue}" }; return $"{x.Type.ToDisplayString()} {x.Name}{optionalValue}"; }
Should be fixed in 2.0.0
@ChristianSauer the issue came back in 2.0.1
Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.6.4 AutomaticInterface: 1.6.0
Method with non-null defaults on Boolean parameters throw CS0103 error. Sample method call:
Reason: The case of the default value is converted to True or False instead of true or false in the GetMethodSignature method. https://learn.microsoft.com/en-us/dotnet/api/system.boolean?view=net-7.0#converting-to-and-from-boolean-values
Fix: Add an additional case to the swtich statement: bool => $" = {Convert.ToString(x.ExplicitDefaultValue, CultureInfo.InvariantCulture).ToLowerInvariant()}",
AutomaticInterface.cs method "GetMethodSignature" with the fix applied: