BCoelho

Hi everyone.

I'm facing another challenge...

This time I want to add some domain proprieties when the generated designer loads, via code.

Imagine that I have a Domain Class that is mapped to a Compartment Shape. When the designer loads I want to add Compartments and Fields that appear when I choose "Add Field".

It was great if I could know the points of extensibility, via code, of the my generated designer. Just like in ASP.NET we have a known set of events that we can choose to handle.

Thank you.

BCoelho


Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

DuncanP - MSFT

Hi there,

I don't quite understand what you want to do: do you want to add new elements to your model whenever it is opened, or when the user takes some action

Extensibility points: unfortunately we don't have all of the extensibility points documented in a single place. There are a lot of them, and they are spread across the layers that make up your target designer (e.g. core VS extensibility, the Managed Package Framework, the runtime DSL libraries and options in the Dsl Designer such setting "custom" or "double derived" = true). The best starting points are probably the MSDN documentation on the Dsl Tools and VSIP, or this forum.

Duncan





Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

BCoelho

I have some domain proprieties in a Domain Class named "A".

When I run the generated designer I can see those domain proprieties in the "Proprieties" window (right-click on the element + proprieties).

What I want to do is to add some domain proprieties to that element via code when the designer loads.

Something like this in pseudo-code:

Code Snippet

public override Designer_OnLoad()

{

foreach(ModelElement elem in Diagram.Elements)

{

elem.AddDomainPropriety(...);

}

}

When the designer has finished the loading event, the user could see the new domain proprieties that were added via code.

Imagine that I want to set the domain proprieties for an element based on something that I only know at runtime... how can I solve this

Thank you for your time.

BCoelho





Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

BCoelho

DuncanP - MSFT wrote:

Extensibility points: unfortunately we don't have all of the extensibility points documented in a single place. There are a lot of them...

Duncan



By extensibility points I'm referring to events that we can choose to handle.

Any ideas on how to resolve my other question

Thanks,
BCoelho




Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

BCoelho

Using ModelElement.GetDomainClass() I'm able to get a DomainClassInfo. This class shows me all the domain proprieties of my ModelElement but only through a ReadOnlyCollection...

However, I can add elements to a LinkedElementCollection that belongs to a Compartment...

I'm still searching for an event that represents the Load event of the generated designer...

Any help is highly appreciated!

Thank you,
BCoelho






Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

DuncanP - MSFT

One way to do this is to override the [MyLanguage]DocData.OnDocumentLoaded() method and make the changes there e.g.

Code Snippet

partial class MyLanguageDocData
{
protected override void OnDocumentLoaded()
{
base.OnDocumentLoaded();

// Find all of the Comment objects in the store
ReadOnlyCollection<Comment> comments = this.Store.ElementDirectory.FindElements<Comment>();

using (Transaction t = this.Store.TransactionManager.BeginTransaction("Update on load"))
{
foreach (Comment c in comments)
{
// Update values on c.
}

t.Commit();

}

}

}

Does this do what you want

Duncan





Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

DuncanP - MSFT

You can't dynamically add new properties to your model elements in instances of your target models at runtime - you can only set the values of existing properties. Are you trying to add new properties

Duncan





Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

BCoelho

Yes, I am trying to add new properties at runtime... but I can see now that these properties belong to an object in memory that is already created... so I can't easily add new properties to this object...

And if I use Reflection.Emit to create a new object in runtime that extends the type of the object that I'm trying to add new proprieties

BCoelho




Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

Edward Bakker

Hi,

Maybe you can try an approach where you "hide" properties based on the situation (state) your model is in

If so, you might be interested in this post.

Edward





Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

BCoelho

DuncanP - MSFT wrote:

You can't dynamically add new properties to your model elements in instances of your target models at runtime - you can only set the values of existing properties. Are you trying to add new properties

Duncan



After imaging many solutions I've finally accepted DucanP's answer... in the end a DomainClass is transformed into a .NET Type. At runtime, you can't modify the generated Type...

I've decided to create another element that will hold the dynamic proprieties and have a connector between that element and the "parent" element.

Thank you all for your time and effort.

BCoelho




Re: Visual Studio Extensibility Add Domain Proprieties (via code) on designer load

DuncanP - MSFT

You might be interested in the thread "Extending a designer post-deployment": http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=393260&SiteID=1.

There is also some rather out of date sample code in a project called "ExtensibleDsl" at http://www.gotdotnet.com/Workspaces/Workspace.aspx id=dae43a90-7893-493c-804a-e1f7537732c0 that does something similar (i.e. adds another element to hold a dynamic property), although this code defines additional properties that are then added to all instances of domain class. Unfortunately, the code was written against a CTP so probably won't work directly against the released Dsl Tools.

Duncan