Simple types such as string's and int's are nice but if you really want to leverage you DSL and use you types you need a couple of things:
1) You need to add it to the DSL designer
2) You need to serialize it somehow
The first part is not very hard there two ways to do it:
1) Edit you DslDefinition.dsl in xml editor – look for //Types/ExternalType and add one of your owns (don’t forget to reference the assembly)
2) You can use DSL Explorer window and add it from there – just click on the root node (you language) and then “Add External Type”

Regarding the second part it’s a little bit tricky:
1) you need to create a “CustomCode” Directory and then add Serializer.cs and remove the “.CustomCode” suffix from the namespace.
2) Now if you element is in ExampleElement then you will have set IsCustom = true on DSL Explorer->Xml Serialization Behavior->ExampleElement.

3) Click “Transform All Templates” and just fix the build errors by implementing the custom seralization/deserialization in Serializer.cs you’ve created in step 1 (use partial class called ExampleElementSerializer) you can look on the other model elements for examples.
I know that the serialization/deserialization is a bit hard and I'll try to post on a different approach when it will be applicable.
Update: Duncan has pointed out another way - serialize you model to xml and then use T4 to generate your hand crafted stuff from in-memory model - check out his samle,
A colleague at work refered me to this post on how to add a menu to a DSL.
Top level summery of the steps needed:
Step#1: Modify Commands.vsct
Step#2: Modify Package version
Step #3: Search for "your" CommandSet class
Step#4: Customize your specific CommandSet
Step #5 : Transform Templates + Test It
Very cool !
When testing WPF forms on WinForms hosting WPF controls you'll probably get test run error: One of the background threads threw exception: System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
Here is a quick sample of code that causes this problem:
class MyDialog
{
public bool Show()
{
System.Windows.Window w = new System.Windows.Window();
w.Show();
}
}
And here's the unit test
using System.Windows.Threading;
[TestClass()]
public class MyDialogTest
{
[TestCleanup]
public void TestCleanup()
{
// Fixing RCW separated problem
Dispatcher.CurrentDispatcher.InvokeShutdown();
}
[TestMethod()]
public void CanShow()
{
MyDialog dialog = new MyDialog();
dialog.Show();
}
}
Try commenting TestCleanup and see what happends...
This week in the blog carnival modeling, T4, C# 4.0, framework desing, SOA, performance and ASP.NET related links.
Modeling and UML
T4
C# 4.0
Framework design
ASP.NET/ASP.NET MVC /WPF /SIlverlight
SOA
Performance
My collègue Jean-Marc has published a lab that should cover a lot of ground in DSL Tools terms.
Check it out