diff --git a/Version.props b/Version.props index 3799ab2..c2abecd 100644 --- a/Version.props +++ b/Version.props @@ -20,9 +20,9 @@ - 1.29.1 + 1.29.2 3.0.84 - 2.2.9 + 2.2.12 5.3.0 5.3.0 3.3.4 diff --git a/src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.cs b/src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.cs index 7593101..a3f8025 100644 --- a/src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.cs +++ b/src/ErrorOrX.Generators/Analyzers/ErrorOrEndpointAnalyzer.cs @@ -1,3 +1,4 @@ +using ANcpLua.Roslyn.Utilities; using ErrorOr.Generators; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; @@ -388,8 +389,7 @@ private static bool IsErrorOr(ITypeSymbol type) // Extract pattern from constructor arguments var patternIndex = attrName.Contains("ErrorOrEndpoint") ? 1 : 0; - if (attr.ConstructorArguments.Length > patternIndex && - attr.ConstructorArguments[patternIndex].Value is string p) + if (attr.GetConstructorArgument(patternIndex) is { } p) { pattern = p; } diff --git a/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.Initialize.cs b/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.Initialize.cs index be4441e..97a6f1d 100644 --- a/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.Initialize.cs +++ b/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.Initialize.cs @@ -1,4 +1,5 @@ using ANcpLua.Roslyn.Utilities.Models; +using ANcpLua.Roslyn.Utilities; using ErrorOr.Analyzers; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -477,8 +478,7 @@ private static (HttpVerb? Verb, string Pattern, string? CustomMethod) ExtractHtt // Extract pattern - index differs for ErrorOrEndpoint (has httpMethod arg first) var patternIndex = isErrorOrEndpoint ? 1 : 0; - var pattern = attr.ConstructorArguments.Length > patternIndex && - attr.ConstructorArguments[patternIndex].Value is string p + var pattern = attr.GetConstructorArgument(patternIndex) is { } p ? p : "/"; diff --git a/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.ParameterBinding.cs b/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.ParameterBinding.cs index 1920e85..f52d30b 100644 --- a/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.ParameterBinding.cs +++ b/src/ErrorOrX.Generators/Core/ErrorOrEndpointGenerator.ParameterBinding.cs @@ -1,4 +1,5 @@ using System.Text.RegularExpressions; +using ANcpLua.Roslyn.Utilities; using ANcpLua.Roslyn.Utilities.Matching; using ANcpLua.Roslyn.Utilities.Models; using ErrorOr.Analyzers; @@ -860,9 +861,9 @@ private static (bool IsNullable, bool IsNonNullableValueType) GetParameterNullab var matcher = new AttributeNameMatcher(WellKnownTypes.FromKeyedServicesAttribute); var attr = parameter.GetAttributes().FirstOrDefault(a => matcher.IsMatch(a.AttributeClass)); - if (attr is null || attr.ConstructorArguments.Length is 0) return null; + if (attr is null) return null; - var val = attr.ConstructorArguments[0].Value; + var val = attr.GetConstructorArgument(0); return val switch { string s => $"\"{s}\"", null => null, _ => val.ToString() }; } @@ -892,8 +893,7 @@ private static bool HasParameterAttribute(ISymbol parameter, ErrorOrContext cont } } - if (attr.ConstructorArguments.Length > 0 && - attr.ConstructorArguments[0].Value is string ctorArg && + if (attr.GetConstructorArgument(0) is { } ctorArg && !string.IsNullOrWhiteSpace(ctorArg)) { return ctorArg; diff --git a/src/ErrorOrX.Generators/ErrorOrX.Generators.csproj b/src/ErrorOrX.Generators/ErrorOrX.Generators.csproj index c75bf04..3b73aa4 100644 --- a/src/ErrorOrX.Generators/ErrorOrX.Generators.csproj +++ b/src/ErrorOrX.Generators/ErrorOrX.Generators.csproj @@ -29,8 +29,15 @@ ANcpLua.Roslyn.Utilities.Sources (AsyncBatchingWorkQueue, IncrementalValuesProviderExtensions). These are deliberate try/catch patterns in resilient infrastructure code. .editorconfig cannot suppress diagnostics in NuGet cache paths. + + AL0140: The generator emitter code intentionally relies on local type inference for + Roslyn syntax construction where explicit types add noise rather than safety. + + RS1035: ANcpLua.Roslyn.Utilities.Sources contains environment-variable checks in + source-package infrastructure; suppress here until the upstream package removes that + analyzer-host API usage. --> - $(NoWarn);NU5128;RS1038;ERP022 + $(NoWarn);NU5128;RS1038;ERP022;AL0140;RS1035 true true false diff --git a/src/ErrorOrX.Generators/OpenApiTransformerGenerator.cs b/src/ErrorOrX.Generators/OpenApiTransformerGenerator.cs index 9408966..943e05f 100644 --- a/src/ErrorOrX.Generators/OpenApiTransformerGenerator.cs +++ b/src/ErrorOrX.Generators/OpenApiTransformerGenerator.cs @@ -1,3 +1,4 @@ +using ANcpLua.Roslyn.Utilities; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; @@ -110,8 +111,7 @@ private static IncrementalValuesProvider CreateEndpointProv private static string GetPattern(AttributeData attr) { - if (attr.ConstructorArguments.Length > 0 && - attr.ConstructorArguments[0].Value is string p && + if (attr.GetConstructorArgument(0) is { } p && !string.IsNullOrWhiteSpace(p)) { return p; @@ -122,10 +122,8 @@ attr.ConstructorArguments[0].Value is string p && private static (string? httpMethod, string? pattern) GetBaseAttributeInfo(AttributeData attr) { - if (attr.ConstructorArguments.Length < 2) return (null, null); - - var method = attr.ConstructorArguments[0].Value as string; - var pattern = attr.ConstructorArguments[1].Value as string; + var method = attr.GetConstructorArgument(0); + var pattern = attr.GetConstructorArgument(1); return string.IsNullOrWhiteSpace(method) ? (null, null)