use of Browsable attribute

use of Browsable attribute

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


rd_bigdog posted on Wednesday, April 30, 2008

Hi Folks,

I have come to an empass in terms of how much I like the use of the Browsable attribute for defining whether or not a field/property should be mapped by the DataMapper. The more I move along in my project, I find that perhaps the use of this attribute in this fashion is more of a convenience thing than a good design (just attempting to spark the discussion).

We all know what the intent of the Browsable attribute is, IE. creating custom components and defining whether or not items are viewable in the designer. This creates a caveat with the CSLA's use of the attribute.

For example, I have classes that have a derived property based on the current culture of the application. I have a propery for an English description and a property for a French description (retrieved from database). I have a DTO with those fields and I map the object nicely to the corresponding fields BO->DTO->BO from server to client.

When binding my list to things like a data grid, I need to specify to the data grid to bind to either english or French depending on the client's culture specification. What I have done is created another property called CultureSpecificDescription which returns either the English or French Description based on current thread culture.

What I don't want to do is have custom code in my BO to case on culture when retrieving the BO data. I want to keep the pattern very simple and since we allow our users to change the culture on the fly, I don't want to have to retrieve from the database each time.

So, what I have done is created  a custom attribute called Mappable and replaced the implementatio that checks for IsBrowsable with IsMappable on the new attribute. Of course, I had to apply this attribute to other areas in the CSLA Base objects.

By using this custom attribute, I can select my public properyt at design time for data binding where Browsable hides the property.

This might be more academic as there are different ways to solve the problem. I am just curious to know if anyone else has come accross this type of issue? It would seem that the proper solution is a custom attribute instead of using the Browsable attribute for something that it may not have been entirely intended for??

Looking forward to any feedback.

Thanks.

Copyright (c) Marimer LLC