How to get the PropertyInfo for a DataRow from its PropertyDescriptor.
//pd is a PropertyDescriptor
var propertyinfo = pd.ComponentType.GetProperty(pd.Name);
the above code works fine for a list collection, but it not works while am working with DataTable.
Any idea on this?
PropertyInfois the reflection world, where types have explicit CLI properties.DataTabledoes not belong to that world; it uses theSystem.ComponentModelflexible property model, viaTypeDescriptor,PropertyDescriptor, etc. Basically: there is no property in the CLI sense.PropertyDescriptorcan be used (and is used) to describe "properties" in a more flexible, dynamic sense, where the layout is not specified as a type, but is custom-defined, often on-the-fly at runtime.So no: you can't do this. The question does not make sense; or at least, in the general case it doesn't. There is also "typed datasets", but frankly I strongly recommend staying far far away from them.
Incidentally, you can invent your own pseudo-properties for any type - there are extension points for this (
TypeDescriptor,ITypedList,ICustomTypeDescriptor,TypeConverter, etc); but only code that explicitly usesSystem.ComponentModelwill ever see them.