Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static method referenced inside an interpolated string #115

Closed
space-alien opened this issue Sep 2, 2024 · 0 comments
Closed

Static method referenced inside an interpolated string #115

space-alien opened this issue Sep 2, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@space-alien
Copy link

I'm using v4.0.0-preview4

This property:

[Projectable]
public string Status => IsDeceased
    ? "Deceased" + (DeceasedDate != null ? $" ({DeceasedDate.Value.ToDateString()})" : "")
    : "";

Generates this code:

static global::System.Linq.Expressions.Expression<global::System.Func<global::MyApp.MyModel, string>> Expression()
{
    return (global::MyApp.MyModel @this) => @this.IsDeceased ? "Deceased" + (@this.DeceasedDate != null ? $" ({global::MyApp.Extensions.ToDateString(@this.DeceasedDate.Value)})" : "") : "";
}

Which won't compile because in $" ({global::MyApp.Extensions.... - the colon (:) is a special character and breaks the generated interpolated string.

I think perhaps the fix would be to wrap the static method in parenthesis, e.g.:

return (global::MyApp.MyModel @this) => @this.IsDeceased ? "Deceased" + (@this.DeceasedDate != null ? $" ({(global::MyApp.Extensions.ToDateString(@this.DeceasedDate.Value))})" : "") : "";
@koenbeuk koenbeuk added the bug Something isn't working label Sep 2, 2024
koenbeuk added a commit that referenced this issue Oct 22, 2024
Add parenthesis inside string interpolations (Fixes #115)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants