Skip to content

Support for data member usage within interpolated strings in C# #69

@aalramadan

Description

@aalramadan

The following sample code:

public class MyClass
{
    private string foo = "Hello, world!";
    public void PrintFoo()
    {
        Console.WriteLine($"The value of foo is: {foo}");
    }
}

Gives:

<unit xmlns="http://www.srcML.org/srcML/src" revision="1.0.0" language="C#" filename="untitled">
<class><specifier>public</specifier> class <name>MyClass</name>
<block>{
    <decl_stmt><decl><type><specifier>private</specifier> <name>string</name></type> <name>foo</name> <init>= <expr><literal type="string">"Hello, world!"</literal></expr></init></decl>;</decl_stmt>
    <function><type><specifier>public</specifier> <name>void</name></type> <name>PrintFoo</name><parameter_list>()</parameter_list>
    <block>{<block_content>
        <expr_stmt><expr><call><name><name>Console</name><operator>.</operator><name>WriteLine</name></name><argument_list>(<argument><expr><name>$</name><literal type="string">"The value of foo is: {foo}"</literal></expr></argument>)</argument_list></call></expr>;</expr_stmt>
    </block_content>}</block></function>
}</block></class></unit>

Where it uses the field foo within an interpolated string.

As of now, Stereocode does not collect the usage of such data members (e.g., fields or methods).

A potential solution would be to collect every interpolated string and then extract the expressions between the { and } for further processing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions