Skip to content

Static method referenced inside an interpolated string #115

@space-alien

Description

@space-alien

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))})" : "") : "";

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions