So, I have two custom complex types (this is simplified for this example):
public class PendingProduct { public string Name { get; set; } public string Description { get; set; } public int ColorCount { get; set; } }
Let's say I need this object to know how to transform myself into another type:
public class Product { public string Name { get; set; } public string Description { get; set; } public ProductColors Colors { get; set;} }
Therefore, when I call the method to convert PendingProduct to Product, I execute some custom logic that adds the ColorCount number to the ProductColor objects in the Product class. This is completely simplified, but the architecture of this class does not really matter.
What is my main question:
What best practice method can be used to implement the conversion of one complex type to another complex type when the properties of objects are different?
In the real world, the properties are very different, and I will write some user logic to match what I need from Object A to Object B.
Obviously, I could just write a function that takes an input parameter Object A and returns Object B, but I'm looking for a more "Best Practice" method. Is IConvertible included here? Is there something more like OOP that I can use rather than just write a function to do what I want?
Object A must always know how to transform itself into object B.
EDIT: As a basic note in the real world, Object A and Object B are Entity Framework 4 objects. I want to take the "Pending Product", convert it to a new Product object, bind it to the data context and save.
c # oop entity-framework entity-framework-4
Scott
source share