diff --git a/Generate-ReleaseNotes.bat b/Generate-ReleaseNotes.bat index 69a1974..9f7365d 100644 --- a/Generate-ReleaseNotes.bat +++ b/Generate-ReleaseNotes.bat @@ -1,6 +1,6 @@ rem https://github.com/StefH/GitHubReleaseNotes -SET version=0.0.20 +SET version=0.0.21 GitHubReleaseNotes --output "ReleaseNotes.md" --skip-empty-releases --exclude-labels question invalid doc --version %version% diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000..65e107f Binary files /dev/null and b/resources/icon.png differ diff --git a/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs b/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs index e7a6bee..1d32edd 100644 --- a/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs +++ b/src/ProxyInterfaceSourceGenerator/Extensions/ParameterSymbolExtensions.cs @@ -6,25 +6,17 @@ namespace ProxyInterfaceSourceGenerator.Extensions; internal static class ParameterSymbolExtensions { - // private const string ParameterValueDefault = "default"; private const string ParameterValueNull = "null"; public static string GetRefPrefix(this IParameterSymbol ps) { - switch (ps.RefKind) + return ps.RefKind switch { - case RefKind.In: - return "in "; - - case RefKind.Out: - return "out "; - - case RefKind.Ref: - return "ref "; - - default: - return string.Empty; - } + RefKind.In => "in ", + RefKind.Out => "out ", + RefKind.Ref => "ref ", + _ => string.Empty + }; } public static string GetParamsPrefix(this IParameterSymbol ps) => @@ -40,7 +32,17 @@ internal static class ParameterSymbolExtensions string defaultValue; if (ps.ExplicitDefaultValue == null) { - defaultValue = ps.Type.IsReferenceType ? ParameterValueNull : $"default({ps.Type})"; + if (ps.NullableAnnotation == NullableAnnotation.Annotated) + { + // The parameter is defined as Nullable, so always use "null". + defaultValue = ParameterValueNull; + } + else + { + defaultValue = ps.Type.IsReferenceType + ? ParameterValueNull : // The parameter is a ReferenceType, so use "null". + $"default({ps.Type})"; // The parameter is not a ReferenceType, so use "default(T)". + } } else { diff --git a/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj b/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj index d178ced..35bee15 100644 --- a/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj +++ b/src/ProxyInterfaceSourceGenerator/ProxyInterfaceSourceGenerator.csproj @@ -1,7 +1,7 @@ - 0.0.20 + 0.0.21 netstandard2.0 {12344228-91F4-4502-9595-39584E5ABB34} 10 @@ -12,14 +12,13 @@ ProxyInterfaceGenerator This project uses Source Generation to generate an interface and a Proxy class for classes. This makes it possible to wrap external classes which do not have an interface, in a Proxy class which makes it easier to Mock and use DI. class;interface;proxy;SourceGenerator;Analyzer;Generation;Generate;wrap - MIT $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../../PackageReleaseNotes.txt")) https://github.com/StefH/ProxyInterfaceGenerator git https://github.com/StefH/ProxyInterfaceGenerator PackageReadme.md - + icon.png false true $(BaseIntermediateOutputPath)Generated @@ -33,32 +32,31 @@ + - all runtime; build; native; contentfiles; analyzers; buildtransitive - - + - + ProxyClassesGenerator.cs - +