Simple scaffolding

Method invocation parameters scaffolding

MappingGenerator provides a set of code fixes that allow for scaffolding parameters of method and constructor invocations. They are offered for the following compiler errors: - CS7036 - There is no argument given that corresponds to the required formal parameter. - CS1501 - No overload for method ‘method’ takes ‘number’ arguments - CS1729 - ‘type’ does not contain a constructor that takes ‘number’ arguments.

Complete invocation with local scope

With Scaffold invocation with local variables (regular arguments) and Scaffold invocation with local variables (named arguments) code actions you can complete method/constructor invocation by automatically substituting variables available in the current scope for missing parameters based on naming and type matching conventions.

For method invocation:

public static class UserService
{
    public static void RegisterUser(string login, string email)
    {
        var id = GenerateNextId();
        var authentication = GetDefaultAuthentication();
        
        // ERROR CS7036: Use MappingGenerator to complete the method invocation
        var user = CreateUser();
    }

    private static UserEntity CreateUser(int id, string login, string email, AuthenticationKind authentication)
        => throw new NotImplementedException();
}

Example:

For constructor invocation:

public static class UserService
{
    public static void RegisterUser(string login, string email)
    {
        var id = GenerateNextId();
        var authentication = GetDefaultAuthentication();
        
        // ERROR CS7036: Use MappingGenerator to complete the method invocation
        var user = new UserEntity();
    }
}

public class UserEntity
{
    public  int Id { get; set; }
    public string Login { get; set; }
    public string Email { get; set; }
    public AuthenticationKind Authentication { get; set; }

    public UserEntity(int id, string login, string email, AuthenticationKind authentication)
        => throw new NotImplementedException();
}

Example:

Complete invocation with dummy values

Using Scaffold invocation with dummy values (regular arguments) and Scaffold invocation with dummy values (named arguments) code actions, you can complete method invocation parameters with dummy constant values:

Splatting

There’s an option called Generate splatting with value parameters that allows completing method/constructor invocation by matching properties of an incorrectly passed object to method parameters.

Mapping lambda

MappingGenerator provides also a special code action Create mapping lambda that completes invocation of Select and ConvertAll methods with mapping expression. More details about this feature can be found in Mapping Lambda section.