I have more classes with several common properties.
e.g.
class A
{
string Class_A_Prop1{g et; set;}
string Class_A_Prop2{g et; set;}
string CommonProp1{get ; set;} // common to all classes
string CommonProp2{get ; set;}
}
class B
{
string Class_B_Prop1{g et; set;}
string Class_B_Prop2{g et; set;}
string CommonProp1{get ; set;} // common to all classes
string CommonProp2{get ; set;}
}
i want to write generic method (without using reflection)
which will display properties CommonPorp1 and CommonProp2
something like this
void DisplayCommon<T >(T entity)
{
string p1=entity.Commo nProp1;
string p2 = entity.CommonPr op2;
Console.WriteLi ne("{0} {1}",p1,p2);
}
keep in mind that class A & B are generated by a external tool
and I do not want to alter them in any way,
so forget solutions that are using abstract classes, inheritance and
interfaces
is this possible in C# using generics or anonymous types?
e.g.
class A
{
string Class_A_Prop1{g et; set;}
string Class_A_Prop2{g et; set;}
string CommonProp1{get ; set;} // common to all classes
string CommonProp2{get ; set;}
}
class B
{
string Class_B_Prop1{g et; set;}
string Class_B_Prop2{g et; set;}
string CommonProp1{get ; set;} // common to all classes
string CommonProp2{get ; set;}
}
i want to write generic method (without using reflection)
which will display properties CommonPorp1 and CommonProp2
something like this
void DisplayCommon<T >(T entity)
{
string p1=entity.Commo nProp1;
string p2 = entity.CommonPr op2;
Console.WriteLi ne("{0} {1}",p1,p2);
}
keep in mind that class A & B are generated by a external tool
and I do not want to alter them in any way,
so forget solutions that are using abstract classes, inheritance and
interfaces
is this possible in C# using generics or anonymous types?
Comment