Does the use of explicit / explicit conversion operators violate the single responsibility pattern in favor of DRY?

I need to convert between the two classes and want to support DRY but not break the single responsibility pattern ...

public class Person
{
    public string Name {get;set;}
    public int ID {get;set;}
}

public class PersonEntity : TableServiceEntity
{
    public string Name {get;set;}
    public int ID {get;set;}

    // Code to set PartitionKey
    // Code to set RowKey
}

Additional Information

I have some Model objects in my ASP.NET MVC application. Since I work with Azure storage, I see the need to often convert to a ViewModel and from a ViewModel and AzureTableEntity.

I usually did this left-right assignment of variables in my controller.

Q1

Besides the implicit / explicit conversion, should this code reside in a controller (x)or datacontext (y)?

Person <--> View <--> Controller.ConverPersonHere(x?) <--> StorageContext.ConvertPersonHere(y?) <--> AzurePersonTableEntity

Q2

Should I do an implicit or explicit conversion?

Q3

Which object should contain the conversion code?


Update

WCF , . . .

+2
1

Q1: .

Q2: , AutoMapper.

Q3: , . , IConverter , IPersonConverter , .

public interface IConverter<TModel, TViewModel>
{
    TViewModel MapToView(TModel source);
}

public interface IPersonConverter : IConverter<PersonEntity, Person>
{
}

public class PersonConverter : IPersonConverter
{
    #region IPersonConverter

    public Person MapToView(PersonEntity source)
    {
        return new Person
                   {
                       ID = source.ID,
                       Name = source.Name
                   };

        //or use an AutoMapper implementation
    }

    #endregion
}
+1

Source: https://habr.com/ru/post/1787275/


All Articles