index > Visual Studio Team System - Domain-Specific Language Tools > Using existing Enumerations

Using existing Enumerations


We got the great 'Domain Model Enumeration Designer' in the DSL tools to design new enums and use them as value properties of classes. But I have some value properties on my DSL elements on which I want to use an already existing enum type. Like for example the 'System.DayOfWeek' enum.

There is some kind of mechanism for this for the simple types: you can point to a namespace and type in the name of the type. Is there something similar for enums? Sure I can look up the literals in the documentation and type in al these literals in the Enum Designer, but that's quite time consuming.

Gerben [Avanade]

gerbenvl

Hi Gerben,

To use an existing enum, do the following:

- Select the property in question on the domain model designer.

- In the property-grid, click on the drop-down for "Type"

- Select "New Simple Type..." in the drop-down.

- In the dialog, enter "System" for Namespace and "DayOfWeek" for and Name. Hit OK.

Let me know if this doesn't work for you.

Thanks,
George Mathew
DSL Tools Team

George Mathew

Hi George,

gerbenvl

Hi Gerben,

I see the issue now. My fault for not giving you full information. When you choose a 'New Simple Type..." for the Type of your property, the 'Custom storage' for that property is also set to true (look for 'Custom storage' on the property grid when the property is selected). When 'Custom storage' is true, it means that you are responsible for providing storage for this property. To do that, add a partial declaration for your class and add the code below:

namespace CompanyName.ProjectName.Language3.DomainModel
{
public partial class ExampleClass
{

System.DayOfWeek property1Storage;

public override object GetValueForCustomStoredAttribute(Microsoft.VisualStudio.Modeling.MetaAttributeInfo attribute)
{
if (attribute.Id == Property1MetaAttributeGuid)
{
return property1Storage;
}
return base.GetValueForCustomStoredAttribute(attribute);
}

public override void SetValueForCustomStoredAttribute(Microsoft.VisualStudio.Modeling.MetaAttributeInfo attribute, object newValue)
{
if (attribute.Id == Property1MetaAttributeGuid)
{
property1Storage = (System.
DayOfWeek)newValue;
}
else
{
base.SetValueForCustomStoredAttribute(attribute, newValue);
}
}
}
}

The experience for doing this will be much better in the next release. Using a external enum won't require your property to be custom stored. Also, if you have a custom stored property, the API for implementing it will be much cleaner and the code will throw a compile-error if the storage is not implemented (unlike the obscure runtime error you got).

Hope this helps.

Thanks,
George Mathew
DSL Tools Team

George Mathew

Cool, that works fine George. Thanks!

Though you guys make me wanna die for the V1 release

Gerben [Avanade]

gerbenvl
Hi,

Is this workaround still valid with the latest ctp we have? I'm having trouble finding "New Simple Type...", and providing custom store will be easier for me than defining domain enumerations since I already got enums somewhere in my code.

Thanks.

Gokhan.
gokhan.altinoren

HI,

It's a little different these days.

What you're looking for now is to add a new external type matching your existing enumeration using the DSL Explorer window. You can then choose this external type as the type of your property.




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

You can use google to search for other answers

 

More Articles

Can Visual Studio DSL Designers be hosted?
Error crearting DSL prokject
Bug in Edit Attributes editor
Installation Problems? "operation is not valid due to the cu...
Change 'arrowStyle' of a connector at runtime
DSL Tools V1 Released
How to make Tree's?
Slip in schedule
Open a new Document
designer definition toolbox item - compartmentTextTool
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

How create an Emf file ? Extending notat…
Open Source Designer
Are these known problems
Setting the default expanded state for a…
"Static" Swimlanes
How access to a connector property
Rules in DSL Tools V1
Toolbox (in the Dsl Designer) only shows…
How to wrap words of one single line to …
Shape inside a shape
Migrating .diagram files to V1 (Septembe…
Package Load Failure - June CTP
Problem running Debug solution
RelationShip ZeroOne-ZeroMany as property
DSL Tools November CTP now available

Hot Articles

Stability of Modeling API
Nesting relationships, can't link to Ima…
DSL and XMI interchange format
GAC support in Templating Engine (Featur…
Load Data designed in another model file
Code Generation Samples Other than HTML?…
How to set the tooltip for the shapes an…
Validation Framework
How access to a connector property
ROM for developing a Use Case cartoon in…
Domain model designer toolbox items disa…
Reflecting domain property value on shap…
How to determine if a model passes valid…
Creating A connector to CompartMent Items
Shape inside a shape

Recommend Articles

Package Load Failure - June CTP
November DSL Toolkit Release: where are …
Any Practical Limits on Model Size?
ROM for developing a Use Case cartoon in…
reuse of model elements
Validation / Rejecting a change from a C…
Open Source Designer
toolbox problem - reset toolbox doesn't …
How can i force the placement of a port …
How to set compartment's default expande…
How to know if OnShapeInserted was initi…
filtering reference dropdowns in the pro…
Many models, one template.
Problem with List type value property
I get a null reference exception when ad…