How to get value of properties interatively?
-
hi all I have this code: foreach (PropertyInfo pi in this.GetType().GetProperties()) { if (pi.Name != "Ds" && !pi.Name.Contains("nmv") && !pi.Name.Contains("Nmv") && pi.Name != "NewId" && pi.Name != "SpeakerID") nmvParams.Add("@" + pi.Name, pi.ToString()); } "this" is my object that contains all the properties. I need to put the name & values of each property into a namevaluecollection nmvParams. pi.Name gives me the name of the property. How do I get the actual value? pi.ToString() just gives me the name of the property in string. thanks M
-
hi all I have this code: foreach (PropertyInfo pi in this.GetType().GetProperties()) { if (pi.Name != "Ds" && !pi.Name.Contains("nmv") && !pi.Name.Contains("Nmv") && pi.Name != "NewId" && pi.Name != "SpeakerID") nmvParams.Add("@" + pi.Name, pi.ToString()); } "this" is my object that contains all the properties. I need to put the name & values of each property into a namevaluecollection nmvParams. pi.Name gives me the name of the property. How do I get the actual value? pi.ToString() just gives me the name of the property in string. thanks M
object propval = pi.GetValue(this, new object[0]);
-
object propval = pi.GetValue(this, new object[0]);
thanks. I figured it out, its actually pi.GetValue(this, null) but you have to check for null before you run it. M