CodeGenerationUtilities Class

Definition

Utilities used by the code-generation templates

public ref class CodeGenerationUtilities abstract sealed
public static class CodeGenerationUtilities
type CodeGenerationUtilities = class
Public Class CodeGenerationUtilities
Inheritance
CodeGenerationUtilities

Fields

CoreDomainModelNamespacePrefix

Methods

AddSerializationResourceStrings(Dictionary<String,KeyValuePair<String,String>>)

Add resource strings used by generated serializers. The string added here are not localized, because they're used to generate resx file, which will be localized.

AllowMultiple(DomainRole)

Gets if the given role allows multiple instances, based on its Multiplicity.

CalculateInheritanceDepth(DomainClass)

Given a DomainClass, calculate the inheritance depth in generated code (taking into consideration of double-derived base classes). This is used to determine whether we need a SuppressMessage attribute for "excessive inheritance".

CreateXmlNamespaceQualifiers(DslLibrary)

Create xmlNamespaceQualifiers for the dslLibrary and its first-level imported libraries

DefinesDiagramElements(DslLibrary)

True if the given DslLibrary defines diagram elements, false otherwise. Diagram elements are elements that are included in DslLibrary.DiagramElements, plus diagram (if one is defined).

DefinesNewTargetRole(DomainRelationship)

In relationship derivation, a relationship can use the same target role-player as its parent relationship, or it can define a new one (which derives from the parent relationship's target role-player). This method tells whether the given DomainRelationship defines a new target role- player.

GenerateFontStyle(FontStyle)

Create the correct syntax for initializing a font's style.

GetAccessModifier(AccessModifier)

Gets the C# access modifier keyword for the given AccessModifier enum

GetAttributeProperties(DomainClass, Int32)

Returns all DomainProperties defined on the given DomainClass that will be serialized as XML attribute.

GetBaseClass(DomainClass, String)

Gets the string for declaring the base class of a domain class. If the base class is not defined, ModelElement is used.

GetBaseDomainClass(DomainClass)

Get the base domain class for the supplied class

GetBaseDomainClassMonikerSchemaTypeName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the moniker schema type name for the base class of the given domain class.

GetBaseDomainClassMonikerTagName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the MonikerTagName for a the base class of the supplied domain class when it is serialized as a moniker. Note that the tag name cannot be the same for moniker, because that will require two definitions of the same element in the generated schema. The default name used (if not specified using "XmlClassData.MonikerElementName"), will be the non-moniker XmlTagName followed by "Moniker".

GetBaseDomainClassSchemaTypeName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the schema type name for the base class of the given domain class.

GetBaseDomainClassXmlTagName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the XmlTagName for the base class of the supplied domain class.

GetBasePropertyHandlerName(DomainProperty)

Gets the base class for the PropertyHandler for the given property. The base class is different if it's a calculated property.

GetBaseRelationship(DomainRelationship)

Gets the string for declaring the base relationship of a domain relationship. If the base class is not defined, ElementLink is used.

GetBaseRole(DomainRole)

Gets the base role of the given role if one exists. If not, it returns null.

GetCamelCase(String)

Conver the input string to camel case by lower-casing the first character

GetDesigner(DslLibrary)

Get the Designer defined in the given DslLibrary.

GetDiagramElementForDecoratorMap(DecoratorMap)

Gets the diagram element associated with the shape or connector map that defines a decorator map.

GetDomainClassMonikerSchemaTypeName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the moniker schema type name for the given domain class.

GetDomainClassMonikerTagName(DomainClass, String)

Get the MonikerTagName for a domain class, when it is serialized as a moniker. Note that the tag name cannot be the same for moniker, because that will require two definitions of the same element in the generated schema. The default name used (if not specified using "XmlClassData.MonikerElementName"), will be the non-moniker XmlTagName followed by "Moniker".

GetDomainClassMonikerTagName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the MonikerTagName for a domain class, when it is serialized as a moniker. Note that the tag name cannot be the same for moniker, because that will require two definitions of the same element in the generated schema. The default name used (if not specified using "XmlClassData.MonikerElementName"), will be the non-moniker XmlTagName followed by "Moniker".

GetDomainClassSchemaTypeName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the schema type name for the given domain class.

GetDomainClassXmlTagName(DomainClass, String)

Get the XmlTagName for a domain class.

GetDomainClassXmlTagName(DomainClass, String, Dictionary<DslLibrary,String>)

Get the XmlTagName for a domain class.

GetDomainTypeFullName(DomainProperty)

Gets the full name of the type of the DomainProperty (including generic parameters) relative to the namespace of the property's class.

GetDomainTypeFullName(DomainType, String)

Gets the full name of the DomainType (including generic parameters) relative to the given current namespace.

GetElementProperties(DomainClass, Int32)

Returns all DomainProperties defined on the given DomainClass that will be serialized as nested XML element.

GetGeneratedLinkAccessModifier(DomainRelationship)

Returns the most limited type access modifier among the passed in DomainRelationship and its role players.

GetGeneratedPropertyGetterAccessModifier(DomainRole)

Returns the getter property modifier to be used for the Get/Set properties in the DomainRelationship class

GetGeneratedPropertySetterAccessModifier(DomainRole)

Returns the setter property modifier to be used for the Get/Set properties in the DomainRelationship class

GetGenerationClassName(DomainClass)

Returns the name of the class to be generated. In the case of a double-derived class, we add 'Base' to the name of the domain class. If not, the name of the domain class is used.

GetGenerationInheritanceModifier(DomainClass)

Gets the class modifier for a domain class. Returns "abstract" if the class is a double derived class because the generated class (base class) in a double-derived pair is always abstract

GetGuid(Guid)

Returns a string of the form "new System.Guid(xxx)" where xxx is the string form of the given guid.

GetInheritanceModifier(InheritanceModifier)

Gets the C# modifier keyword for the given InheritanceModifier enum

GetMethodModifier(Boolean, Boolean)

Gets the method modifier (virtual, override, etc.) in generated code with the given parameters.

GetModelElementDomainClass(Store)

Returns the DomainClass that represents ModelElement

GetNameProperty(DomainClass)

Return a property (in this or a base class) that can be used to idenfify an element to the user. Returns the property marked IsElementName. If there is none, returns the property marked IsMonikerKey. If there is none, returns null.

GetPackageNamespace(Dsl)

Get Dsl package name for the given Dsl.

GetPropertyDefaultValue(DomainProperty, Boolean)

Returns the string to declare the default value of a property (in the form "= defaultValue"

GetPropertyDefaultValueAttribute(DomainProperty)

Gets the string for the constructor of the System.ComponentModel.DefaultValueAttribute.

GetPropertyHandlerName(DomainProperty)

Gets the name of a property handler for a property

GetPropertyKind(PropertyKind)

Returns the string for the kind of the kind of the property for the DomainPropertyAttribute constructor.

GetPropertyRepresentation(DomainProperty)

Get the PropertyRepresentation (Attribute, Element, or Ignored) of the given DomainProperty. Default is Attribute if not specified.

GetPropertyTagName(DomainProperty)

Gets the XML tag name of the given DomainProperty. The tag name will be either the XML attribute name if the property is serialized as an XML attribute, or XML element name if the property is serialized as a nested XML element.

GetRelationshipTagName(DomainRole)

Get the XML role element name for the given role's relationship. Note: this is the RoleElementName (if defined), not the XML tag name for a full-form relationship (which is returned from GetDomainClassXmlTagName()).

GetSameNameBaseRole(DomainRole)

Returns the base role of the given role if it has the same name as the given role

GetSegmentInputType(PathSegment)

For the given pathSegment, this method returns its input fully qualified type name.

GetSegmentInputType(PathSegment, Boolean)

For the given pathSegment, this method returns its input fully qualified type name.

GetSegmentOutputType(PathSegment)

For the given pathSegment, this method returns its output fully qualified type name.

GetSegmentOutputType(PathSegment, Boolean)

For the given pathSegment, this method returns its output fully qualified type name.

GetSerializedDomainClasses(DslLibrary)

Get a list of all DomainClasses in the given DslLibrary that will have serializers generated.

GetTypeAccessModifier(TypeAccessModifier)

Gets the C# access modifier keyword for the given TypeAccessModifier enum

GetTypeRole(DomainRole)

Gets the role that determines the type of the generated property for this role. This is the most-base role that has the same name as this role.

GetVersionString(DslLibrary)

Get the version of a DslLibrary in string form.

GetXmlSchemaNamespace(DslLibrary)

Get the XML namespace to use for the generated schema

HasCompartmentMaps(Diagram)

True if the given Diagram defines CompartmentMaps.

HasCustomBaseImplementation(DomainClass)
Obsolete.

Whether the given DomainClass (or any of its base DomainClasses) is marked as "IsCustom", which means the serialization is customized.

HasCustomTypeDescriptor(DomainClass)

Returns true if the given class has a custom type descriptor defined, false otherwise.

HasNonAbstractBaseClass(DomainClass)

Tells if the given DomainClass has a non-abstract base class. There is needed to determine if a "new" keyword needs to be generated.

IsCoreDomainModel(DslLibrary)

Returns whether the supplied class is the Core domain model

IsElementLinkDomainClass(DomainClass)

Returns whether the supplied domain class represents "ElementLink".

IsGuidType(String)

returns true if typeName represents Guid ("System.Guid")

IsInCoreDomainModel(DomainClass)

Returns whether the supplied class is part of the Core domain model

IsLaxElementSchemaRequired(DomainClass)

Whether a lax element schema type definition is required for the class

IsModelElementDomainClass(DomainClass)

Returns whether the supplied domain class represents "ModelElement".

IsMultiple(Multiplicity)

returns true if the upper bound of the given multiplicity is *

IsOuterDecorator(DiagramElementHasDecorators)

Returns true if the given link connects to an outer decorator.

IsOuterDecorator(ShapeDecoratorPosition)

Returns true if the given ShapeDecorationPosition is an outer decorator.

IsRootClass(DomainClass)

If a DomainClass is a root class, all its serialization-related methods/properties will be virtual (unless it's sealed); otherwise, these methods/properties will be "override" and will call base implementations. Currently, a DomainClass is a root class if it derives from Microsoft.VisualStudio.Modeling.ModelElement or Microsoft.VisualStudio.Modeling.ElementLink directly.

IsStringProperty(DomainProperty)

returns true if the property is of type string.

IsStringType(String)

returns true if typeName represents a string ("string" or "System.String")

MapToSchemaType(DomainType)

Map a DomainType to its schema type.

OmitElement(DomainRelationship)

Gets if the given DomainRelationship is serialized as "OmitElement" (without the role element tag).

RequiresGeneratedPropertyDescriptor(CustomPropertyDescriptor)

Returns true if the given descriptor requires a PropertyDescriptor derived class to be generated, false otherwise.

SortDomainClassesByInheritance<T>(IEnumerable<T>)

Sort a collection of DomainClasses based on relative inheritance relationships. The most derived one will appear first in the sort result. This is used in following situation: Say there're 4 DomainClasses A, B, C and D. You need to generate some code like following: ... A a = obj as A; if (a != null) ... B b = obj as B; if (b != null) ... C c = obj as C; if (c != null) ... D d = obj as D; if (d != null) ... ... If C derives from A, the above code is wrong; the correct code should check for C first before checking for A. That's why this method should be called to sorted the DomainClasses in inheritance order, and the generated code will look like: ... C c = obj as C; if (c != null) ... A a = obj as A; if (a != null) ... B b = obj as B; if (b != null) ... D d = obj as D; if (d != null) ... ...

SortProperties(IList<DomainProperty>)

Sort DomainProperties based on XmlElement.Order (if specified). By default, the order of each property is 0. Properties with smaller order will appear first. Properties of the same order will not be sorted (i.e. they'll keep their relative order after sorting). The sorting is in-place, so the passed-in collection will be changed directly.

SortRoles(IList<DomainRole>)

Sort DomainRoles based on XmlRelationshipElement.Order (if specified). By default, the order of each role is 0. Roles with smaller order will appear first. Roles of the same order will not be sorted (i.e. they'll keep their relative order after sorting). The sorting is in-place, so the passed-in collection will be changed directly.

UseFullForm(DomainRelationship)

Gets if the given DomainRelationship is serialized in full-form.

WrapAsCSharpString(String)

Wrap the given string into a string literal in C# syntax.

Applies to