c# - Getting collection of all members of a class -


i want collection of members present in class. how do that? using following, giving me many names along members.

type obj  =  objcontactfield.gettype(); memberinfo[] objmember = obj.getmembers(); string name = objmember[5].name.tostring(); 

if want collection of properties , there values, :

class test {     public string name { get; set; } }  test instance = new test(); type type = typeof(test);  dictionary<string, object> properties = new dictionary<string, object>(); foreach (propertyinfo prop in type.getproperties())     properties.add(prop.name, prop.getvalue(instance)); 

note, need add using system.collections.generic; , using system.reflection; example work.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -