-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump update * Bump update * Bump update * Migrating to generating all SysML model * Need to add deep search * SC Meeting updates * Success! * Update .gitignore * Included packages * Added static root model - MtconnectModel is the intended entry point into the MTConnect SysML model. - Successful build * Transpiled code * Update MtconnectTranspiler.Sinks.CSharp.csproj * Re-ran transpiler * Updated transpiler * Transpiler updates - Fixed DefaultValue - Fixed Generalization - Added property inheritance - Fixed naming to match SysML * Expanded Enum definitions * Set EnumMetaClass as instance type * Bump update * Bump update * Update Program.cs * Bump update * Logging * Update Program.cs * Bump update * Bump update * Update CSharp.Class.scriban * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Update CSharp.Class.scriban * Bump update * Update summary access to comments * Updated all summary templates * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Added summary prefix * Reintroduced includes for summaries * Updated all summaries - Fully implemented new MarkdownInterpreter and CodeFormatter for converting SysML Comments into different formats. * Update MtconnectTranspiler.Sinks.CSharp.csproj * Updated navigator * Update UmlCommentsSummaryContent.scriban * Include Enums in Packages - Added Enums to Packages - Removed unnecessary XML summary prefixes (///) * Added Profile Packages - Added Profile Packages to root MtconnectModel * Applied new keyword Attempting to override the IClass.Properties with the custom PropertyList * Update MtconnectTranspiler.Sinks.CSharp.csproj * Added virtual/overrides to classes * Update MtconnectTranspiler.Sinks.CSharp.csproj * Changed SuperClass to Category Changed property name/type to reflect observation type categories * Added help info - Added ReferenceId to IEnum - Added HelpUrl property and constant to IClass, IEnum, and IPackage - Refactored "normative remarks" in XML summary. * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Introducing constant strings * Added XML summary for constants * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Suppress obsolete warnings in generated code * Transpiled with latest * Added help url - Added help url to observation type in navigation extensions * Attempted fix at navigating summary for types/sub-types * Ordinal comparison - Changed comparison of Observation Type names ordinal with a removal of '_' characters on both sides between IClass and IEnum comparisons * Scoped sub-types * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Addressed debug environment * Update MtconnectTranspiler.Sinks.CSharp.Example.csproj * Ran transpiler - Used the Example transpiler to generate files * Update MtconnectTranspiler.Sinks.CSharp.csproj * Update MtconnectTranspiler.Sinks.CSharp.csproj
- Loading branch information
Showing
1,387 changed files
with
299,294 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
175 changes: 175 additions & 0 deletions
175
MtconnectTranspiler.Sinks.CSharp.Example/Models/CSharpClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
using CaseExtensions; | ||
using MtconnectTranspiler.CodeGenerators.ScribanTemplates; | ||
using MtconnectTranspiler.Sinks.CSharp.Example; | ||
using MtconnectTranspiler.Xmi; | ||
using MtconnectTranspiler.Xmi.UML; | ||
|
||
namespace MtconnectTranspiler.Sinks.CSharp.Models | ||
{ | ||
/// <summary> | ||
/// Represents a C# class | ||
/// </summary> | ||
[ScribanTemplate("CSharp.Class.scriban")] | ||
public partial class CSharpClass : CsharpType, IFileSource | ||
{ | ||
/// <summary> | ||
/// Reference to the xmi:id | ||
/// </summary> | ||
public string? ReferenceId { get; set; } | ||
|
||
/// <summary> | ||
/// Reference to the <c>name</c> attribute. | ||
/// </summary> | ||
public string? NormativeName { get; set; } | ||
|
||
/// <summary> | ||
/// Reference to any Comments written in the SysML model to be converted into a C# format <c><summary /></c> | ||
/// </summary> | ||
public Summary? Summary { get; protected set; } | ||
|
||
/// <summary> | ||
/// Internal reference to the class filename. | ||
/// </summary> | ||
protected string? _filename { get; set; } | ||
/// <inheritdoc /> | ||
public virtual string Filename | ||
{ | ||
get | ||
{ | ||
if (string.IsNullOrEmpty(_filename)) | ||
_filename = $"{CategoryFunctions.ToPathSafe(Namespace.Substring(Namespace.LastIndexOf(".")+1))}/{CategoryFunctions.ToPathSafe(Name.ToPascalCase())}.cs"; | ||
return _filename; | ||
} | ||
set { _filename = value; } | ||
} | ||
|
||
/// <summary> | ||
/// Internal list of <see cref="Property"/>, used by <see cref="Properties"/>. | ||
/// </summary> | ||
protected List<Property> _properties = new List<Property>(); | ||
/// <summary> | ||
/// Collection of <inheritdoc cref="Property"/> | ||
/// </summary> | ||
public IEnumerable<Property> Properties => _properties; | ||
|
||
/// <summary> | ||
/// Internal list of <see cref="Constraint"/>, used by <see cref="Constraints"/>. | ||
/// </summary> | ||
protected List<Constraint> _constraints = new List<Constraint>(); | ||
/// <summary> | ||
/// Collection of <inheritdoc cref="Constraint"/> | ||
/// </summary> | ||
public IEnumerable<Constraint> Constraints => _constraints; | ||
|
||
/// <summary> | ||
/// Remote type of the generalization | ||
/// </summary> | ||
public string? Generalization { get; set; } | ||
|
||
/// <summary> | ||
/// Original <c>generalization</c> value from the XMI | ||
/// </summary> | ||
public string? GeneralizationId { get; set; } | ||
|
||
private XmiElement? _remoteType { get; set; } | ||
|
||
/// <summary> | ||
/// Constructs an <see cref="CSharpClass"/> more generically. <b>NOTE</b>: You'll need to add items manually from here. | ||
/// </summary> | ||
/// <param name="model"><inheritdoc cref="XmiDocument" path="/summary"/></param> | ||
/// <param name="source"><inheritdoc cref="XmiElement" path="/summary"/></param> | ||
public CSharpClass(XmiDocument model, UmlClass source) : base(model, source) | ||
{ | ||
ReferenceId = source.Id; | ||
|
||
if (source.Comments?.Length > 0) | ||
Summary = new Summary(source.Comments); | ||
|
||
if (source.IsAbstract) | ||
Modifier = "abstract"; | ||
|
||
AccessModifier = "public"; | ||
|
||
_properties = source.Properties | ||
?.Where(o => !string.IsNullOrEmpty(o.Name)) | ||
?.Select(o => new Property(model, o)) | ||
?.ToList() | ||
?? new List<Property>(); | ||
var propertyGroupings = _properties.GroupBy(o => o.Name); | ||
foreach (var propertyGrouping in propertyGroupings) | ||
{ | ||
if (propertyGrouping.Count() <= 1) | ||
continue; | ||
var properties = _properties.Where(o => o.Name == propertyGrouping.Key).ToList(); | ||
foreach (var property in properties) | ||
{ | ||
if (property.Type.EndsWith("Class")) | ||
{ | ||
string remoteClassName = property.Type.Replace("Class", string.Empty); | ||
if (!property.Name.EndsWith(remoteClassName)) | ||
{ | ||
property.Name += remoteClassName; | ||
} | ||
} | ||
} | ||
} | ||
|
||
_constraints = source.Constraints | ||
?.Where(o => !string.IsNullOrEmpty(o.Name)) | ||
?.Select(o => new Constraint(model, o)) | ||
?.ToList() | ||
?? new List<Constraint>(); | ||
|
||
GeneralizationId = source.Generalization?.Name ?? source.Generalization?.General; | ||
if (!string.IsNullOrEmpty(GeneralizationId)) | ||
{ | ||
XmiElement? remoteType = null; | ||
Generalization = CSharpHelperMethods.ToPrimitiveType(GeneralizationId)?.Name | ||
?? CSharpHelperMethods.TypeDeepSearch(model, GeneralizationId, out remoteType) | ||
?? ""; | ||
} | ||
|
||
Name = GetClassName(model, source); | ||
NormativeName = source.Name; | ||
} | ||
|
||
/// <summary> | ||
/// Adds a new <see cref="Property"/> | ||
/// </summary> | ||
/// <param name="property">Reference to the source <see cref="Property"/> to add</param> | ||
public void Add(Property property) | ||
=> _properties.Add(property); | ||
|
||
public static string GetClassName(XmiDocument model, UmlClass umlClass) | ||
{ | ||
string name = CSharpHelperMethods.ToPascalCase(umlClass.Name); | ||
|
||
string? generalization = umlClass.Generalization?.Name ?? umlClass.Generalization?.Id; | ||
if (!string.IsNullOrEmpty(generalization)) | ||
{ | ||
string? generalizedType = CSharpHelperMethods.TypeDeepSearch(model, generalization, out XmiElement? remoteType); | ||
if (!string.IsNullOrEmpty(generalizedType) && generalizedType.EndsWith("Class")) | ||
{ | ||
string remoteGeneralization = generalizedType.Replace("Class", string.Empty); | ||
if (name.EndsWith(remoteGeneralization, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
name += "Generalization"; | ||
} | ||
else | ||
{ | ||
name += "Class"; | ||
} | ||
} | ||
else | ||
{ | ||
name += "Class"; | ||
} | ||
} else | ||
{ | ||
name += "Class"; | ||
} | ||
return name; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.