Explicit conversions

Explicit conversions work like mapping method implementors but the mapping expression is entered inline where the types mismatch is detected. This code fix allows to generate conversion code for the following compiler errors:

⭐ MappingGenerator in premium version allows for tweaking explicit conversions with UI Configurator.

For invalid assignments

public class SampleClass
{
    public AddressDTO Address { get; set; }

    public void DoSomething()
    {
        var addressEntity = new AddressEntity();
        // ERROR CS0029: Try to fix it with MappingGenerator
        this.Address = addressEntity;
    }
}

Example:

For invalid variable declarations:

public class SampleClass
{
    public void DoSomething()
    {
        var addressEntity = new AddressEntity();
        // ERROR CS0029: Try to fix it with MappingGenerator
        AddressDTO address = addressEntity;
    }
}

Example:

For invalid return statement

public class SampleClass
{
    public ReadOnlyCollection<AddressDTO> DoSomething(IList<AddressEntity> addresses)
    {
        // ERROR CS0266: Try to fix it with MappingGenerator
        return addresses;
    }
}

Example:

For invalid yield return statement

public class SampleClass
{

    public IEnumerable<AddressDTO> DoSomething(AddressEntity address)
    {
        // ERROR CS0029: Try to fix it with MappingGenerator
        yield return address;
    }
}

Example:

⭐ Extracting explicit conversion to method

In the premium version, thanks to UI Mapping Configurator, it’s possible to automatically extract generated conversion code to a separated method: