What's an elegant solution to get the property values from two classes (that have the same property

Posted by SlipToFall on Stack Overflow See other posts from Stack Overflow or by SlipToFall
Published on 2010-05-07T08:36:47Z Indexed on 2010/05/07 8:38 UTC
Read the original article Hit count: 199

Essentially I have to deal with a poorly implemented web service. They have two classes that don't derive from a parent class, but have the same properties (Ughh...). So it looks like this in my web service proxy class file:

public partial class Product1
{
    public int Quantity;
    public int Price;
}

public partial class Product2
{
    public int Quantity;
    public int Price;
}

So what's the best way to grab the values from known properties without duplicating the code and casting to their respective classes? I know I probably could use reflection, but that can get ugly. If there is an easier less crazier way to do it (maybe in the new c# features?) please let me know.

© Stack Overflow or respective owner

Related posts about class

Related posts about property