I have a class with a set of properties as given below.
class CustomerInfo
{
public string Address { get; set; }
public string FirstName{ get; set; }
public string LastName{ get; set; }
public string PostCode{ get; set; }
public string Title{ get; set; }
public string Email{ get; set; }
}
I have a method called getinfo(string Fields) which take string field names as parameters like below “FirstName, LastName, Title” based on the parameter fields my method should return only the list with
<CustomerInfo>
<FirstName></FirstName>
<LastName></LastName>
<Title></Title>
</CustomerInfo>
How can I do this in c#?
Public List<CustomerInfo> getinfo(string Fields)
{
List<CustomerInfo> list = new List<CustomerInfo> ();
…….
return list;
}
Please do the needful.
You could do something with refletion like this. I haven’t tried to compile this, but it should be pretty close.