Csla.PropertyInfo<T> and System.ComponentModel.PropertyDescriptor

Csla.PropertyInfo<T> and System.ComponentModel.PropertyDescriptor

Old forum URL: forums.lhotka.net/forums/t/8565.aspx


Regent posted on Tuesday, February 23, 2010

Hi Rocky,

Have you considered inheriting Csla.PropertyInfo<T> from System.ComponentModel.PropertyDescriptor class? You can get a list of properties for a specific class by TypeDescriptor.GetProperties(typeof(ClassName)) and PropertyDescriptor will have a lot of useful properties populated, such as `Converter` (TypeConverter for this property), `IsReadOnly`, `DisplayName`, `Name`, `Description`. (It takes some information from property's attributes like, DescriptionAttribute, DisplayNameAttribute and ReadOnlyAttribute.)

Also currently you use "" as a default friendlyName but I think the most appropriate is to use the one from DisplayName property.

Thanks

ajj3085 replied on Tuesday, February 23, 2010

Not sure that's a good idea, because it uses reflection... which I believe was what PropertyInfo<T> was meant to avoid.

Regent replied on Wednesday, February 24, 2010

Well, PropertyDescriptor by itself is an abstract class and it is not mandatory to use a reflection in order to get a valid instance of PropertyDescriptor. But the one obtained via reflection is widely used by the .NET framework. (when displaying column names in the DataGridView using DisplayName, using ReadOnly or using TypeConverter for interpreting string data to another type.)

RockfordLhotka replied on Wednesday, February 24, 2010

PropertyDescriptor doesn't exist in Silverlight, so it isn't useful in the general case.

RockfordLhotka replied on Thursday, February 25, 2010

Regent

Also currently you use "" as a default friendlyName but I think the most appropriate is to use the one from DisplayName property.

There is an item in the wish list to pull the friendly name from the DisplayName attribute when RegisterProperty() is invoked. That got a little more complicated now with DataAnnotations though, since I think they defined yet another friendly name attribute to check for...

The upside is that the new attribute in DataAnnotations supports localization, which was one reason the older DisplayName attribute wasn't ideal.

Regent replied on Friday, February 26, 2010

I haven't noticed DataAnnotations' DisplayAttribute... Looks like it is indeed a better way for specifying friendly name. Perhaps when RegisterProperty is called it should look for DisplayAttribute and fall back to DisplayNameAttribute if wasn't found?

RockfordLhotka replied on Friday, February 26, 2010

This is almost certainly what we'll do, yes.

Copyright (c) Marimer LLC