I have a method in C# which I need to pass the ObservableCollection to thaat method. I need to get the properties and their values in class T. However, my class T can be any class name.
e.g.:
public class MyClass
{
public string prop1 {get; set;}
public prop2 {get; set; }
}
public class OtherClass
{
public string OtherProp1 {get; set;}
public OtherProp2 {get; set;}
}
private ObservableCollection<MyClass> _myselectedItems = new ObservableCollection<MyClass>();
public ObservableCollection<MyClass> MySelectedItems
{
get{return _myselectedItem;}
set{_myselectedItem = value;}
}
private ObservableCollection<OtherClass> _otherselectedItems = new ObservableCollection<OtherClass>();
public ObservableCollection<OtherClass> OtherSelectedItems
{
get{return _otherselectedItem;}
set{_otherselectedItem = value;}
}
public GenericMethod<T>(ObservableCollection<T> anySelectedItems)
{
if (anySelectedItems[0].**prop1** != "Hello")
{ // do something
}
}
I have this generic method that I want to call.
----> here I want to be able to get to the corresponding properties of the class (e.g. prop1, prop2, otherProp1, or OtherProp2) based on where this method is called and type of anySelectedItems. If the pass value is ObservableCollection<MyClass>
then I need to get the prop1 and prop2.
Any suggestion is appreciated. Thanks.