diff --git a/src/TypedSignalR.Client.DevTools.Specification/SourceGenerator.cs b/src/TypedSignalR.Client.DevTools.Specification/SourceGenerator.cs index 294b48e..34d33a2 100644 --- a/src/TypedSignalR.Client.DevTools.Specification/SourceGenerator.cs +++ b/src/TypedSignalR.Client.DevTools.Specification/SourceGenerator.cs @@ -81,13 +81,7 @@ private static SourceSymbol TransformToSourceSymbol(GeneratorSyntaxContext conte return default; } - if (arguments[0].Expression.Kind() != SyntaxKind.StringLiteralExpression) - { - return default; - } - - var literal = arguments[0].Expression as LiteralExpressionSyntax; - var path = literal?.Token.ValueText; + var path = GetPath(context, arguments[0].Expression); if (string.IsNullOrEmpty(path)) { @@ -104,6 +98,33 @@ private static SourceSymbol TransformToSourceSymbol(GeneratorSyntaxContext conte return new SourceSymbol(methodSymbol, target.GetLocation(), path!); } + private static string? GetPath(GeneratorSyntaxContext context, ExpressionSyntax syntax) + { + if (syntax.Kind() == SyntaxKind.StringLiteralExpression + && syntax is LiteralExpressionSyntax literal) + { + return literal.Token.ValueText; + } + + var symbol = context.SemanticModel.GetSymbolInfo(syntax).Symbol; + + if (symbol is IFieldSymbol field + && field.IsConst + && field.ConstantValue is string fieldValue) + { + return fieldValue; + } + + if (symbol is ILocalSymbol local + && local.IsConst + && local.ConstantValue is string localValue) + { + return localValue; + } + + return null; + } + private static ValidatedSourceSymbol ValidateMapHubMethodSymbol((SourceSymbol, SpecialSymbols) pair, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested();