Stereotypes Examples
Example: Stereotypes added to a Code Generator
We can see that the EF4 Code Generator has the Stereotypes open. Under the Property Stereotypes there is an "EF Primary Key" Stereotype.
So when the Code Generator is added to a model and a Property is selected. The "EF Primary Key" Stereotype with now appear in the Properties windows and will allow you to enter a value in this field.
Example: Adding serialization stereotypes to a code generator
In this example we will add the "CanSerialize" stereotype to the code generator. Then we will update the code generator to use this new stereotype.
Now that the stereotypes have been added to the Code Generator we need to update the Code Generator Template to use this new stereotypes.
To access the stereotype in code use the following syntax
element["Code Generator Name","Stereotype"]
So for the CanSerialize stereotype
property["Code Generator Name","CanSerialize"]
So we if update the C# Poco Generators Template to Support Serialization it would look like this
@using SilverDawn.SilverModel.UML.Extensions;
@using SilverDawn.SilverModel.UML.Interfaces.Classes;
@using SilverDawn.SilverModel.UML.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SilverDawn.SilverModel.UML.Interfaces.Classes;
namespace SampleCode
{
@if (Model.Classifier["Default","CanSerialize"]=="True")
{
@:[DataContract]
}
public class @Model.Classifier.Name
{
@foreach (var att in Model.Classifier.Properties())
{
if (att["C#Serialization","CanSerialize"]=="True")
{
@:[DataMember]
}
<text>public @Model.RazorSupport.LookupDataType("C#",att.DataTypeId)</text> @att.Name <text> { get; set; } </text>
}
}
}
and this will product the following code, for the Todo Class(see ToDo sample Model)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SilverDawn.SilverModel.UML.Interfaces.Classes;
namespace SampleCode
{
[DataContract]
public class Todo
{
[DataMember]
public int TodoId { get; set; }
[DataMember]
public string TaskName { get; set; }
[DataMember]
public DateTime DateCreated { get; set; }
[DataMember]
public DateTime DateDue { get; set; }
}
}