A
Arial
I have more classes with several common properties.
e.g.
class A
{
string Class_A_Prop1{get; set;}
string Class_A_Prop2{get; set;}
string CommonProp1{get; set;} // common to all classes
string CommonProp2{get; set;}
}
class B
{
string Class_B_Prop1{get; set;}
string Class_B_Prop2{get; 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.CommonProp1;
string p2 = entity.CommonProp2;
Console.WriteLine("{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{get; set;}
string Class_A_Prop2{get; set;}
string CommonProp1{get; set;} // common to all classes
string CommonProp2{get; set;}
}
class B
{
string Class_B_Prop1{get; set;}
string Class_B_Prop2{get; 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.CommonProp1;
string p2 = entity.CommonProp2;
Console.WriteLine("{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?