PropertyInfo for DataRow from PropertyDescriptor

How to get PropertyInfo for DataRow from PropertyDescriptor.

//pd is a PropertyDescriptor var propertyinfo = pd.ComponentType.GetProperty(pd.Name); 

the above code works fine for a collection of lists, but it doesn't work while working with a DataTable.

Any idea on this?

+4
source share
1 answer

PropertyInfo is a reflection world where types have explicit CLI properties. DataTable does not belong to this world; it uses the flexible property model System.ComponentModel through TypeDescriptor , PropertyDescriptor , etc. Basically: there is no property in the sense of the CLI. PropertyDescriptor can be used (and is used) to describe "properties" in a more flexible, dynamic sense, when the layout is not specified as a type, but is customizable by the user, often on the fly at run time.

So no: you cannot do this. The question does not make sense; or at least in the general case this is not. There are also "typed datasets", but to be honest, I highly recommend staying away from them.

By the way, you can come up with your own pseudo-properties for any type - there are extension points for this ( TypeDescriptor , ITypedList , ICustomTypeDescriptor , TypeConverter , etc.); but only code that explicitly uses System.ComponentModel will ever see them.

+3
source

Source: https://habr.com/ru/post/1497237/


All Articles