Is there a way to associate one custom objects properties to another custom objects properties so that there is an easy means of casting?
For example:
I have an object called degree which has two columns: TypeID, TypeName I have another object called typelist which also has two columns: _id, _typename
I would like to be able to perform the following: degree _dg = (degree)typelistitem
without having to explicitly say _dg.TypeID = typelistitem._id
There is nothing built-in in the C# language.
Of course, you could write a helper method, provide it with a map from class X properties to class Y properties, but what would be the point? Compare:
with
Is the former really more readable or more concise? You need to write down which property of X gets mapped to which property of Y anyway, and the latter example only adds 8 chars of overhead to each line (
y.? = x.?;
), so I really don't think that a more general solution is worth the effort.