Class ClassGenerator<T>
Represents a base class for a transformation rule that generates classes
public abstract class ClassGenerator<T> : TransformationRule<T, CodeTypeDeclaration> where T : class
Type Parameters
TThe model element type from which the classes are generated
- Inheritance
-
ClassGenerator<T>
- Derived
- Inherited Members
-
TransformationRule<T, CodeTypeDeclaration>.Transform(T, CodeTypeDeclaration, ITransformationContext)TransformationRuleBase<T, CodeTypeDeclaration>.MarkInstantiatingFor<TBaseIn, TBaseOut>(Predicate<T>)TransformationRuleBase<T, CodeTypeDeclaration>.TraceOutput<TKey>(Func<T, CodeTypeDeclaration, TKey>)
Methods
AddImplementationBaseClass(CodeTypeDeclaration)
Modifies the given code declaration to respect that the generated class is the root of an inheritance tree
protected virtual void AddImplementationBaseClass(CodeTypeDeclaration generatedType)
Parameters
generatedTypeCodeTypeDeclarationThe generated class declaration
Remarks
This method can be overridden so that the derived transformation rule can inherit common base functionality
CreateInterfaceMembers(T, CodeTypeDeclaration, CodeTypeDeclaration, ITransformationContext)
Generates the interface members for the given type
protected virtual void CreateInterfaceMembers(T input, CodeTypeDeclaration generatedType, CodeTypeDeclaration interfaceDecl, ITransformationContext context)
Parameters
inputTThe input for which the interface members need to be generated
generatedTypeCodeTypeDeclarationThe generated type
interfaceDeclCodeTypeDeclarationThe interface declaration
contextITransformationContextThe transformation context
CreateOutput(T, ITransformationContext)
Creates the output the transformation rule
public override CodeTypeDeclaration CreateOutput(T input, ITransformationContext context)
Parameters
inputTThe input model element
contextITransformationContextThe transformaton context
Returns
- CodeTypeDeclaration
A new code type declaration with set reference that references back to the code declaration
CreateSeparatePublicInterface(T, CodeTypeDeclaration)
Create a separate public interface for the given input
protected virtual CodeTypeDeclaration CreateSeparatePublicInterface(T input, CodeTypeDeclaration generatedType)
Parameters
inputTThe input model element
generatedTypeCodeTypeDeclarationThe generated type declaration
Returns
- CodeTypeDeclaration
A new type declaration without members or null, if no interface shall be created.
GetName(T)
Gets the name of the class generated for the given model element
protected abstract string GetName(T input)
Parameters
inputTThe input model element
Returns
- string
The name of the class
RequireBaseClass(Func<T, T>)
Creates a dependency to generate the code for the base classes of the current class
public ITransformationRuleDependency RequireBaseClass(Func<T, T> selector)
Parameters
selectorFunc<T, T>A function used to select the model element from which to generate a base class
Returns
- ITransformationRuleDependency
The transformation rule dependency
RequireBaseClass<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration>, Func<T, TClass>)
Creates a dependency to generate the code for the base classes of the current class
public ITransformationRuleDependency RequireBaseClass<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration> rule, Func<T, TClass> selector) where TClass : class
Parameters
ruleTransformationRuleBase<TClass, CodeTypeDeclaration>The transformation rule that is used to generate the class
selectorFunc<T, TClass>A function used to select the model element from which to generate a base class
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TClassThe model element type from which to generate the base class
RequireBaseClasses(Func<T, IEnumerable<T>>)
Creates a dependency to generate the code for the base classes of the current class
public ITransformationRuleDependency RequireBaseClasses(Func<T, IEnumerable<T>> selector)
Parameters
selectorFunc<T, IEnumerable<T>>The function used to select the model elements from which to generate the base classes
Returns
- ITransformationRuleDependency
The transformation rule dependency
RequireBaseClasses<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration>, Func<T, IEnumerable<TClass>>)
Creates a dependency to generate the code for the base classes of the current class
public ITransformationRuleDependency RequireBaseClasses<TClass>(TransformationRuleBase<TClass, CodeTypeDeclaration> rule, Func<T, IEnumerable<TClass>> selector) where TClass : class
Parameters
ruleTransformationRuleBase<TClass, CodeTypeDeclaration>The transformation rule that is used to generate the base classes
selectorFunc<T, IEnumerable<TClass>>The function used to select the model elements from which to generate the base classes
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TClassThe model element type from which to generate the base classes
RequireEvent<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent>, Func<T, TEvent>)
Creates a dependency to generate an event from a given subsequent model element
public ITransformationRuleDependency RequireEvent<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent> rule, Func<T, TEvent> selector) where TEvent : class
Parameters
ruleTransformationRuleBase<TEvent, CodeMemberEvent>The transformation rule that is used to generate the event
selectorFunc<T, TEvent>The selector function that selects the model element from which to generate an event
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TEventThe model element type from which to generate an event
RequireEvents<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent>, Func<T, IEnumerable<TEvent>>)
Creates a dependency to generate events from given subsequent model elements
public ITransformationRuleDependency RequireEvents<TEvent>(TransformationRuleBase<TEvent, CodeMemberEvent> rule, Func<T, IEnumerable<TEvent>> selector) where TEvent : class
Parameters
ruleTransformationRuleBase<TEvent, CodeMemberEvent>The transformation rule to generate events
selectorFunc<T, IEnumerable<TEvent>>The selector function that selects the model elements from which to generate events
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TEventThe model element type from which to generate events
RequireGenerateMethod<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod>, Func<T, TMeth>)
Cregates a dependency to generate a method from a given subsequent model element
public ITransformationRuleDependency RequireGenerateMethod<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod> rule, Func<T, TMeth> selector) where TMeth : class
Parameters
ruleTransformationRuleBase<TMeth, CodeMemberMethod>The method generator
selectorFunc<T, TMeth>The selector function that selects the model element from which to generate the method
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TMethThe model element type from which to generate a method
RequireGenerateMethods<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod>, Func<T, IEnumerable<TMeth>>)
Creates a dependency to generate methods from subsequent model elements
public ITransformationRuleDependency RequireGenerateMethods<TMeth>(TransformationRuleBase<TMeth, CodeMemberMethod> rule, Func<T, IEnumerable<TMeth>> selector) where TMeth : class
Parameters
ruleTransformationRuleBase<TMeth, CodeMemberMethod>The method generator
selectorFunc<T, IEnumerable<TMeth>>The selector function that selects the model elements from which to generate the methods
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TMethThe model elements type from which to generate methods
RequireGenerateProperties<TProp>(TransformationRuleBase<TProp, CodeMemberProperty>, Func<T, IEnumerable<TProp>>)
Creates a dependency to generate properties from subsequent model elements
public ITransformationRuleDependency RequireGenerateProperties<TProp>(TransformationRuleBase<TProp, CodeMemberProperty> rule, Func<T, IEnumerable<TProp>> selector) where TProp : class
Parameters
ruleTransformationRuleBase<TProp, CodeMemberProperty>The transformation rule for the property generation rule
selectorFunc<T, IEnumerable<TProp>>The selector function to select the subsequent model elements
Returns
- ITransformationRuleDependency
The created transformation rule dependency
Type Parameters
TPropThe model element type from which to generate a property
RequireGenerateProperty<TProp>(TransformationRuleBase<TProp, CodeMemberProperty>, Func<T, TProp>)
Creates a dependency to generate a property from a given subsequent model element
public ITransformationRuleDependency RequireGenerateProperty<TProp>(TransformationRuleBase<TProp, CodeMemberProperty> rule, Func<T, TProp> selector) where TProp : class
Parameters
ruleTransformationRuleBase<TProp, CodeMemberProperty>The property generator
selectorFunc<T, TProp>The selector function that selects the model element from which to generate the property
Returns
- ITransformationRuleDependency
The transformation rule dependency
Type Parameters
TPropThe model element type from which to generate a property
ResolveMultipleInheritanceMembers(CodeTypeDeclaration, HashSet<CodeTypeMember>, CodeConstructor)
Resolves the members inherited from multiple base classes
protected virtual void ResolveMultipleInheritanceMembers(CodeTypeDeclaration generatedType, HashSet<CodeTypeMember> shadows, CodeConstructor constructor)
Parameters
generatedTypeCodeTypeDeclarationThe generated type
shadowsHashSet<CodeTypeMember>The members that are shadowed by others
constructorCodeConstructorThe constructor to which initializations should be added
ShouldContainMembers(CodeTypeDeclaration, CodeTypeDeclaration)
Determines whether the provided type should contain members of the given base type
protected virtual bool ShouldContainMembers(CodeTypeDeclaration generatedType, CodeTypeDeclaration baseType)
Parameters
generatedTypeCodeTypeDeclarationThe type that is currently being generated
baseTypeCodeTypeDeclarationThe base types
Returns
- bool
True if so, otherwise false
Transform(T, CodeTypeDeclaration, ITransformationContext)
Initializes the generated type declaration
public override void Transform(T input, CodeTypeDeclaration generatedType, ITransformationContext context)
Parameters
inputTThe input model element
generatedTypeCodeTypeDeclarationThe generated class declaration
contextITransformationContextThe transformation context
Remarks
Can be overridden to refine code generation