C# get name of object as string -
i have object named 'account' , following code:
account objacc = new account(); objacc.name = "test";
the above working fine, expected. have list of values follows:
string props = "name,address,telephone";
now, want see if "name" exists in list. have object use though (hard coding case statement etc isn't possible object dynamic), objacc.name, somehow need "name" that, , see if it's in list.
thanks in advance, hope it's clear enough,
dave
string test = objacc.gettype().getproperty("name") == null ? "" : objacc.gettype().getproperty("name").name; bool result = "name,address,telephone".split(',').contains(test);
you may use following method if like:
public bool propertyexists<t>(string propertyname, ienumerable<string> propertylist,t obj) { string test = obj.gettype().getproperty(propertyname) == null ? "" : obj.gettype().getproperty(propertyname).name; bool result = propertylist.contains(test); return result; }
giannis
Comments
Post a Comment