index > Visual Studio Team System - Domain-Specific Language Tools > Overriding custom attribute in a derived class

Overriding custom attribute in a derived class


In my model, i use the base class "NamedElement" which defines the Name property for all other classes. This property is browsable and updatable but in a derived class, i want to force this property readonly.

How can i override this attribut ?

Can you explain the use of DomainTypeDescriptor ?

Thank you,

Malain

Hi Malain,

DomainTypeDescriptor is currently used to generate code to ADD extra properties to the set exposed on an element (typically seen in the properties grid). You can't use it to override the properties of a base class.

I've raised bugs to this effect, but I don't know whether we'll have time to fix them before V1 now.

You can, however, achieve the same effect in custom code by creating a TypeDescriptionProvider-derived class and attaching it to your derived class. It should return a custom ElementTypeDescriptor-derived class. which has its GetProperties method overridden.

The GetProperties override should call the base GetProperties and then walk the list returned looking for the PropertyDescriptor poining at NamedElement.Name

Replace that PropertyDescriptor instance with your own PropertyDescriptor instance (a class derived from ElementPropertyDescriptor) that has the behavior you want - in this case, you'd return true from IsReadOnly.

A bit long-winded, I'm afraid - this is broadly what the code generator would do for you with a DomainTypeDescriptor. However, using this method does ensure that your objects will behave as you expect in any System.ComponentModel container.




Gareth Jones - Developer - DSL Tools & Software Factories Platform [MSFT]
GarethJ MSFT
Hi Malain,
In addition to what Gareth said, I would say that the specific case you describe (limiting visibility/accessibility to an overriden property) breaks the OO Liskov Substitution Principle and, as a consequence, I strongly suggest that you move the subclass containing the read-only property outside the hierarchy that you created as it cannot really be managed like any other ??amedElement??in your collection interchangeably.

Claudio Perrone

Thank you Claudio,

Yes, i know this is the more "elegant" solution but sometimes the implementation is not trivial and you must do some compromises. (This is a personal opinion)

Kind regards,

Malain

Thank you Gareth,

I had seen this but i hoped a more simplest solution.

Just a suggestion
Is it possible to add a property modifier attribute on a domain property ? Then, i can override my property and add some custom attributes in a custom partial code.

I need the same thing with a role definition. I want to initialize a role when it is used for the first time. The best solution is to override the property's accessors in a partial code and for that, i must be able to indicate that the role is virtual.

Thanks.

Malain
Hi Malain - that's a good suggestion - we won't get to it now in V1, but I'll put it on the list for later versions.


Gareth Jones - Developer - DSL Tools & Software Factories Platform [MSFT]
GarethJ - MSFT
reply 6

You can use google to search for other answers

 

More Articles

Announcing: SharpLudus, a software factory for improved game deve...
What one-shot recipes would you add to DSL Designer?
How to get a reference to a model within code?
[outdated] September 2005 CTP available
Save instance of model in menu command
How to generate Hashtable like collection?
Validation Framework
Interacting with Server Explorer
Toolswindows out of control.
how can i get a reference to a modelelement (ie. ID) betwen two s...
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Fail to load Designer package
How to set the connector decorator posit…
How to update PropertyGrid after changin…
problem when following "Walkthrough…
tutorial
February CTP of DSL Tools is live in the…
Multi-User Capability
Package Load Failure
How to access to the shape connectors by…
UIPAB
Problem with List type value property
missing menu options in visual studio
Reordering items in compartments?
protected internal
Announcing: SharpLudus, a software facto…

Hot Articles

How to update PropertyGrid after changin…
How to Block Self-Relationship
Relationship from CompartmentItem and po…
domain class inheritance, where types ar…
Collaborating on models?
How to get a programmatic reference on t…
Three mystic symbols
End-to-end samples and updated customiza…
Question on using the domain model desig…
Walkthrough distinguish visually between…
How to change the Name property when a S…
UIPAB
CMDS: Missing package guid for commands …
How are new objects created in a DSL?
Problem running Debug solution

Recommend Articles

How can I add existed DataBase scheme to…
How to get a programmatic reference on t…
Package Load Failure - June CTP
A better name for a BlankLanguage
Using DSL tools outside VS
How to Prevent property from being displ…
Serialize reference type class member
missing menu options in visual studio
How to Block Self-Relationship
new connectors
DoubleClick in Compartment item
DSL using languages
Error in "Domain-Specific Language …
How to generate additional property for …
Label Editing (how to prevent)