-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Description
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.