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:
CS0029
- Cannot implicitly convert type ‘type’ to ‘type’CS0266
- Cannot implicitly convert type ‘type1’ to ‘type2’. An explicit conversion exists (are you missing a cast?)CS1503
- The type of one argument in a method does not match the type that was passed when the class was instantiated. ⭐ MappingGenerator in premium version allows for tweaking explicit conversions with UI Configurator.
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:
public class SampleClass
{
public void DoSomething()
{
var addressEntity = new AddressEntity();
// ERROR CS0029: Try to fix it with MappingGenerator
AddressDTO address = addressEntity;
}
}
Example:
return
statementpublic class SampleClass
{
public ReadOnlyCollection<AddressDTO> DoSomething(IList<AddressEntity> addresses)
{
// ERROR CS0266: Try to fix it with MappingGenerator
return addresses;
}
}
Example:
yield return
statementpublic class SampleClass
{
public IEnumerable<AddressDTO> DoSomething(AddressEntity address)
{
// ERROR CS0029: Try to fix it with MappingGenerator
yield return address;
}
}
Example:
public class SampleClass
{
public void DoSomething(UserDTO user)
{
// ERROR CS1503: Try to fix it with MappingGenerator
ProcessAddress(user.Address);
}
private void ProcessAddress(AddressEntity address)
{
}
}
Example:
In the premium version, thanks to UI Mapping Configurator
, it’s possible to automatically extract generated conversion code to a separated method: