diff --git a/Source/Directory.Packages.props b/Source/Directory.Packages.props index 9c7262d..f71de5c 100644 --- a/Source/Directory.Packages.props +++ b/Source/Directory.Packages.props @@ -1,34 +1,34 @@ - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Sundew.DiscriminatedUnions.Generator.Baseline/DeclarationStage/DiscriminatedUnionCaseDeclarationProvider.cs b/Source/Sundew.DiscriminatedUnions.Generator.Baseline/DeclarationStage/DiscriminatedUnionCaseDeclarationProvider.cs index beac6c8..f9b2cf5 100644 --- a/Source/Sundew.DiscriminatedUnions.Generator.Baseline/DeclarationStage/DiscriminatedUnionCaseDeclarationProvider.cs +++ b/Source/Sundew.DiscriminatedUnions.Generator.Baseline/DeclarationStage/DiscriminatedUnionCaseDeclarationProvider.cs @@ -7,14 +7,12 @@ namespace Sundew.DiscriminatedUnions.Generator.DeclarationStage; -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Sundew.DiscriminatedUnions.Generator; using Sundew.DiscriminatedUnions.Generator.Model; using Sundew.DiscriminatedUnions.Generator.OutputStage; using Sundew.DiscriminatedUnions.Shared; @@ -36,15 +34,15 @@ public static IncrementalValuesProvider Setup { var owners = FindOwners(caseNamedTypeSymbol).Select(x => (Type: x.GetSourceType(), ReturnType: x.GetFullType(true), HasConflictingName: HasConflictingName(x, caseNamedTypeSymbol))).ToImmutableArray(); var parameters = TryGetParameters(caseNamedTypeSymbol); - if (parameters == null) + if (parameters == default) { - return null; + return default; } return new DiscriminatedUnionCaseDeclaration(caseNamedTypeSymbol.GetFullType(), owners, parameters.ToImmutableArray()); } - return null; + return default; } private static bool HasConflictingName(INamedTypeSymbol discriminatedUnionNameTypeSymbol, INamedTypeSymbol caseNamedTypeSymbol) @@ -55,19 +53,21 @@ private static bool HasConflictingName(INamedTypeSymbol discriminatedUnionNameTy private static IEnumerable? TryGetParameters(INamedTypeSymbol namedTypeSymbol) { - var selectedConstructor = namedTypeSymbol.Constructors.SkipWhile(x => + var selectedConstructor = namedTypeSymbol.Constructors + .OrderByDescending(x => x.Parameters.Length) + .SkipWhile(x => x.ContainingType.IsRecord && SymbolEqualityComparer.Default.Equals(x.Parameters.FirstOrDefault()?.Type, x.ContainingType)) .FirstOrDefault(); - if (selectedConstructor == null) + if (selectedConstructor == default) { - return null; + return default; } return selectedConstructor.Parameters.Select(x => { var typeName = x.Type.ToDisplayString(CodeAnalysisHelper.FullyQualifiedParameterTypeFormat); - var defaultValue = x.HasExplicitDefaultValue ? x.ExplicitDefaultValue?.ToString() ?? GeneratorConstants.Null : null; + var defaultValue = x.HasExplicitDefaultValue ? x.ExplicitDefaultValue?.ToString() ?? GeneratorConstants.Null : default; return new Parameter(typeName, x.Name.Uncapitalize().AvoidKeywordCollision(), defaultValue); }); } @@ -75,7 +75,7 @@ private static bool HasConflictingName(INamedTypeSymbol discriminatedUnionNameTy private static IEnumerable FindOwners(ITypeSymbol typeSymbol) { var baseType = typeSymbol.BaseType; - while (baseType != null) + while (baseType != default) { if (baseType.IsDiscriminatedUnion()) { @@ -95,7 +95,7 @@ private static bool IsDiscriminatedUnionCaseCandidate(SyntaxNode syntaxNode) { static bool HasBaseListAndIsNotAbstract(TypeDeclarationSyntax typeDeclarationSyntax) { - return typeDeclarationSyntax.BaseList != null && typeDeclarationSyntax.Modifiers.Any(SyntaxKind.SealedKeyword); + return typeDeclarationSyntax.BaseList != default && typeDeclarationSyntax.Modifiers.Any(SyntaxKind.SealedKeyword); } return syntaxNode switch