Skip to content

Missing member used by copied methods with NewType generation #49

@fredericDelaporte

Description

@fredericDelaporte

When generating Async code as new type, constants/fields used by copied methods are not copied.

public class Class1
{
    public void Do()
    {
        DbConnection c = GetConnection();
        c.Open();
    }

    private const string _connectionString = "blah";

    private SqlConnection GetConnection() => new SqlConnection(_connectionString);
}

Get generated as:

public class Class1Async
{
    public Task DoAsync(CancellationToken cancellationToken = default(CancellationToken))
    {
        try
        {
            DbConnection c = GetConnection();
            return c.OpenAsync(cancellationToken);
        }
        catch (System.Exception ex)
        {
            return Task.FromException<object>(ex);
        }
    }

    private static SqlConnection GetConnection() => new SqlConnection(_connectionString);
}

Workaround: declare the field or constant as a property.
For this example, changing it to private static string _connectionString => "blah"; dodge the trouble.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions