From 3689238cb9ca77cbd7fa34dbd15003af87266e36 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 4 Dec 2017 18:44:33 +0200 Subject: Added Code Generation Library. --- .../Visual_Studio/Tango.CodeGeneration/Class.cs | 70 +++++++++ .../Visual_Studio/Tango.CodeGeneration/CodeFile.cs | 34 ++++ .../Tango.CodeGeneration/CodeObject.cs | 134 ++++++++++++++++ .../Tango.CodeGeneration/CodeObjectModifier.cs | 35 +++++ .../Tango.CodeGeneration/DpProperty.cs | 80 ++++++++++ .../Tango.CodeGeneration/FilterGLCodeFile.cs | 17 ++ .../Visual_Studio/Tango.CodeGeneration/Helper.cs | 171 +++++++++++++++++++++ .../Tango.CodeGeneration/ICodeObject.cs | 24 +++ .../Visual_Studio/Tango.CodeGeneration/Method.cs | 83 ++++++++++ .../Tango.CodeGeneration/MethodModifier.cs | 19 +++ .../Tango.CodeGeneration/Namespace.cs | 44 ++++++ .../Properties/AssemblyInfo.cs | 6 + .../Visual_Studio/Tango.CodeGeneration/Property.cs | 77 ++++++++++ .../Tango.CodeGeneration.csproj | 101 ++++++++++++ .../Tango.CodeGeneration/Templates/Class.cshtml | 18 +++ .../Tango.CodeGeneration/Templates/CodeFile.cshtml | 11 ++ .../Templates/DpProperty.cshtml | 8 + .../Tango.CodeGeneration/Templates/Method.cshtml | 4 + .../Templates/Namespace.cshtml | 7 + .../Tango.CodeGeneration/Templates/Property.cshtml | 41 +++++ .../Tango.CodeGeneration/packages.config | 5 + 21 files changed, 989 insertions(+) create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Class.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/CodeFile.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/CodeObject.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/CodeObjectModifier.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/DpProperty.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/FilterGLCodeFile.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Helper.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/ICodeObject.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Method.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/MethodModifier.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Namespace.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Properties/AssemblyInfo.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Property.cs create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/Class.cshtml create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/CodeFile.cshtml create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/DpProperty.cshtml create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/Method.cshtml create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/Namespace.cshtml create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/Templates/Property.cshtml create mode 100644 Software/Visual_Studio/Tango.CodeGeneration/packages.config (limited to 'Software/Visual_Studio/Tango.CodeGeneration') diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Class.cs b/Software/Visual_Studio/Tango.CodeGeneration/Class.cs new file mode 100644 index 000000000..087f07916 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Class.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + public class Class : CodeObject + { + /// + /// Gets or sets the class name. + /// + public String Name { get; set; } + + public List InheritsFrom { get; set; } + + /// + /// Gets or sets the properties. + /// + public List Properties { get; set; } + + /// + /// Gets or sets the dependency properties. + /// + public List DependencyProperties { get; set; } + + /// + /// Gets or sets the methods. + /// + public List Methods { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public Class() + : base() + { + Name = "Class1"; + Properties = new List(); + DependencyProperties = new List(); + Methods = new List(); + InheritsFrom = new List(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + public Class(String name) + : this() + { + Name = name; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// The inherits from. + public Class(String name, params String[] inheritsFrom) + : this(name) + { + if (inheritsFrom != null && inheritsFrom.Length > 0) + { + InheritsFrom = inheritsFrom.ToList(); + } + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/CodeFile.cs b/Software/Visual_Studio/Tango.CodeGeneration/CodeFile.cs new file mode 100644 index 000000000..8e10f0c28 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/CodeFile.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a file code object. + /// + /// + public class CodeFile : CodeObject + { + /// + /// Gets or sets the namespaces. + /// + public List Namespaces { get; set; } + + /// + /// Gets or sets the using section. + /// + public List Usings { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public CodeFile() : base() + { + Namespaces = new List(); + Usings = new List(); + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/CodeObject.cs b/Software/Visual_Studio/Tango.CodeGeneration/CodeObject.cs new file mode 100644 index 000000000..6d7e74960 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/CodeObject.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Web; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a code object base class. + /// + /// + public abstract class CodeObject : ICodeObject + { + /// + /// Initializes a new instance of the class. + /// + public CodeObject() + { + Attributes = new List(); + IndentResult = true; + } + + /// + /// Gets or sets the code object modifier. + /// + public CodeObjectModifier Modifier { get; set; } + + /// + /// Gets or sets the attributes associated with this code object. + /// + public List Attributes { get; set; } + + /// + /// Gets or sets a value indicating whether to indent the resulting code. + /// + public bool IndentResult { get; set; } + + /// + /// Generates the code represented by this code object. + /// + /// + public virtual string GenerateCode() + { + var code = Helper.ParseTemplate(GetTemplate(), this); + + if (IndentResult) + { + code = Helper.IndentCSharpCode(code); + code = RemoveDoubleLines(code); + } + + code = code.Replace(""", "\""); + code = HttpUtility.HtmlDecode(code); + + return code; + } + + /// + /// Removes the double lines. + /// + /// The string. + /// + private String RemoveDoubleLines(string str) + { + String result = String.Empty; + + using (var streamReader = new StringReader(str)) + { + string line = null; + bool previousLineWasBlank = false; + while ((line = streamReader.ReadLine()) != null) + { + if (!string.IsNullOrEmpty(line) || !previousLineWasBlank) + { + result += line +Environment.NewLine; + } + + previousLineWasBlank = string.IsNullOrEmpty(line); + } + } + + return result; + } + + /// + /// Gets the template associated with this code object. + /// + /// + public virtual string GetTemplate() + { + return Helper.GetTemplate(this.GetType()); + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + return GenerateCode(); + } + + /// + /// Gets the modifier string. + /// + /// + public String GetModifierString() + { + return Modifier.ToString().ToLower(); + } + + /// + /// Gets the attributes string. + /// + /// + public String GetAttributesString() + { + if (Attributes != null && Attributes.Count > 0) + { + return String.Join(Environment.NewLine, Attributes); + } + else + { + return null; + } + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/CodeObjectModifier.cs b/Software/Visual_Studio/Tango.CodeGeneration/CodeObjectModifier.cs new file mode 100644 index 000000000..3d6be1b04 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/CodeObjectModifier.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a code object modifiers enumeration. + /// + public enum CodeObjectModifier + { + /// + /// Public modifier. + /// + Public, + /// + /// Internal modifier. + /// + Internal, + /// + /// Protected modifier. + /// + Protected, + /// + /// Private modifier. + /// + Private, + /// + /// No modifier. + /// + None, + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/DpProperty.cs b/Software/Visual_Studio/Tango.CodeGeneration/DpProperty.cs new file mode 100644 index 000000000..dffcaf372 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/DpProperty.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a dependency property code object. + /// + /// + public class DpProperty : CodeObject + { + /// + /// Gets or sets the property name. + /// + public String Name { get; set; } + + /// + /// Gets or sets the property type. + /// + public String Type { get; set; } + + /// + /// Gets or sets the default value. + /// + public String DefaultValue { get; set; } + + /// + /// Gets or sets the owner class. + /// + public String OwnerClass { get; set; } + + /// + /// Gets or sets the property changed callback. + /// + public String PropertyChangedCallback { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public DpProperty() + : base() + { + Name = "MyProperty"; + Type = "int"; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// The type. + /// The default value. + /// The owner class. + public DpProperty(String name, String type, String defaultValue, String ownerClass) + : this() + { + Name = name; + Type = type; + DefaultValue = defaultValue; + OwnerClass = ownerClass; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// The type. + /// The default value. + /// The owner class. + /// The property changed callback. + public DpProperty(String name, String type, String defaultValue, String ownerClass, String propertyChangedCallback) + : this(name, type, defaultValue, ownerClass) + { + PropertyChangedCallback = propertyChangedCallback; + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/FilterGLCodeFile.cs b/Software/Visual_Studio/Tango.CodeGeneration/FilterGLCodeFile.cs new file mode 100644 index 000000000..f560711d0 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/FilterGLCodeFile.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + public class FilterGLCodeFile : Class + { + public FilterGLCodeFile(String name) + : base(name) + { + + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Helper.cs b/Software/Visual_Studio/Tango.CodeGeneration/Helper.cs new file mode 100644 index 000000000..0ca012be9 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Helper.cs @@ -0,0 +1,171 @@ +using RazorEngine; +using RazorEngine.Templating; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + internal static class Helper + { + /// + /// Gets a code template by the code object type. + /// + /// The type. + /// + public static String GetTemplate(Type type) + { + return GetTemplate(type.Name); + } + + /// + /// Gets a code template by name. + /// + /// The name. + /// + public static String GetTemplate(String name) + { + var assembly = Assembly.GetAssembly(typeof(Helper)); + var resourceName = "CodeGenerator.Templates." + name + ".cshtml"; + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (StreamReader reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + + /// + /// Parses the template using Razor Engine. + /// + /// The template. + /// The model. + /// + public static String ParseTemplate(String template, object model) + { + return Engine.Razor.RunCompile(template, Guid.NewGuid().ToString(), model.GetType(), model).Replace("
", "").Replace("
", ""); + } + + /// + /// Indents the c sharp code. + /// + /// The code. + /// + public static string IndentCSharpCode(string code) + { + const string INDENT_STEP = " "; + + if (string.IsNullOrWhiteSpace(code)) + { + return code; + } + + var result = new StringBuilder(); + var indent = string.Empty; + var lineContent = false; + var stringDefinition = false; + + for (var i = 0; i < code.Length; i++) + { + var ch = code[i]; + + if (ch == '"' && !stringDefinition) + { + result.Append(ch); + stringDefinition = true; + continue; + } + + if (ch == '"' && stringDefinition) + { + result.Append(ch); + stringDefinition = false; + continue; + } + + if (stringDefinition) + { + result.Append(ch); + continue; + } + + if (ch == '{' && !stringDefinition) + { + if (lineContent) + { + result.AppendLine(); + } + + result.Append(indent).Append("{"); + + if (lineContent) + { + result.AppendLine(); + } + + indent += INDENT_STEP; + lineContent = false; + + continue; + } + + if (ch == '}' && !stringDefinition) + { + if (indent.Length != 0) + { + indent = indent.Substring(0, indent.Length - INDENT_STEP.Length); + } + + if (lineContent) + { + result.AppendLine(); + } + + result.Append(indent).Append("}"); + + if (lineContent) + { + result.AppendLine(); + } + + + lineContent = false; + + continue; + } + + if (ch == '\r') + { + continue; + } + + if ((ch == ' ' || ch == '\t') && !lineContent) + { + continue; + } + + if (ch == '\n') + { + lineContent = false; + result.AppendLine(); + + continue; + } + + if (!lineContent) + { + result.Append(indent); + lineContent = true; + } + + result.Append(ch); + } + + return result.ToString(); + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/ICodeObject.cs b/Software/Visual_Studio/Tango.CodeGeneration/ICodeObject.cs new file mode 100644 index 000000000..044235813 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/ICodeObject.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a code object. + /// + public interface ICodeObject + { + /// + /// Generates the code represented by this code object. + /// + String GenerateCode(); + + /// + /// Gets the template associated with this code object. + /// + String GetTemplate(); + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Method.cs b/Software/Visual_Studio/Tango.CodeGeneration/Method.cs new file mode 100644 index 000000000..5c460e4dc --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Method.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a method code object. + /// + /// + public class Method : CodeObject + { + /// + /// Gets or sets the method name. + /// + public String Name { get; set; } + + /// + /// Gets or sets the method arguments. + /// + public List> Arguments { get; set; } + + /// + /// Gets or sets the method return type. + /// + public String ReturnType { get; set; } + + /// + /// Gets or sets the method modifier. + /// + public MethodModifier MethodModifier { get; set; } + + /// + /// Gets or sets the method content. + /// + public String Content { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public Method() + : base() + { + Name = "MyMethod"; + Arguments = new List>(); + ReturnType = "void"; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// Type of the return. + /// The content. + /// The method modifier. + public Method(String name, String returnType, String content, MethodModifier methodModifier = Tango.CodeGeneration.MethodModifier.None) + : this() + { + Name = name; + ReturnType = returnType; + Content = content; + MethodModifier = methodModifier; + } + + /// + /// Gets the arguments string. + /// + /// + public String GetArgumentsString() + { + if (Arguments.Count > 0) + { + return String.Join(", ", Arguments.Select(x => x.Key + " " + x.Value).ToList()); + } + else + { + return String.Empty; + } + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/MethodModifier.cs b/Software/Visual_Studio/Tango.CodeGeneration/MethodModifier.cs new file mode 100644 index 000000000..df64a877f --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/MethodModifier.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a method modifier enumeration. + /// + public enum MethodModifier + { + None, + Virtual, + Override, + Internal, + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Namespace.cs b/Software/Visual_Studio/Tango.CodeGeneration/Namespace.cs new file mode 100644 index 000000000..85464713b --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Namespace.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a namespace code object. + /// + /// + public class Namespace : CodeObject + { + /// + /// Gets or sets the namespace name. + /// + public String Name { get; set; } + + /// + /// Gets or sets the classes section. + /// + public List Classes { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public Namespace() + : base() + { + Classes = new List(); + Modifier = CodeObjectModifier.None; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + public Namespace(String name) : this() + { + Name = name; + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Properties/AssemblyInfo.cs b/Software/Visual_Studio/Tango.CodeGeneration/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..251d04060 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +[assembly: AssemblyTitle("Tango - Code Generation Components")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Property.cs b/Software/Visual_Studio/Tango.CodeGeneration/Property.cs new file mode 100644 index 000000000..d7ca5f4a8 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Property.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CodeGeneration +{ + /// + /// Represents a property code object. + /// + /// + public class Property : CodeObject + { + /// + /// Gets or sets the property name. + /// + public String Name { get; set; } + + /// + /// Gets or sets the property type. + /// + public String Type { get; set; } + + /// + /// Gets or sets the property setter modifier. + /// + public CodeObjectModifier SetterModifier { get; set; } + + /// + /// Gets or sets a value indicating whether this property has a setter. + /// + public bool HasSetter { get; set; } + + /// + /// Gets or sets the content of the setter. + /// + public String SetterContent { get; set; } + + /// + /// Gets or sets the content of the getter. + /// + public String GetterContent { get; set; } + + /// + /// Gets the private field. + /// + /// + public virtual String GetPrivateField() + { + return "_" + Name.ToLower(); + } + + /// + /// Initializes a new instance of the class. + /// + public Property() + : base() + { + Name = "MyProperty"; + Type = "int"; + SetterModifier = CodeObjectModifier.None; + } + + /// + /// Initializes a new instance of the class. + /// + /// The name. + /// The type. + public Property(String name, String type) + : this() + { + Name = name; + Type = type; + } + } +} diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj new file mode 100644 index 000000000..989cfdf8d --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Tango.CodeGeneration.csproj @@ -0,0 +1,101 @@ + + + + + Debug + AnyCPU + {CAEDAE94-11ED-473C-888A-268A6D38CD20} + Library + Properties + Tango.CodeGeneration + Tango.CodeGeneration + v4.5 + 512 + SAK + SAK + SAK + SAK + + + true + full + false + ..\Build\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + false + + + + + + + + ..\packages\RazorEngine.3.10.0\lib\net45\RazorEngine.dll + + + + + + + + + + + + + GlobalVersionInfo.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/Class.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Class.cshtml new file mode 100644 index 000000000..693fe9136 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Class.cshtml @@ -0,0 +1,18 @@ + @(Model.GetAttributesString()) + @(Model.GetModifierString()) class @(Model.Name) @(Model.InheritsFrom.Count > 0 ? " : " + String.Join(", ",Model.InheritsFrom) : null) + { + @foreach (var prop in Model.Properties) + { +
@prop.GenerateCode()
+ } + + @foreach (var dp in Model.DependencyProperties) + { +
@dp.GenerateCode()
+ } + + @foreach (var method in Model.Methods) + { +
@method.GenerateCode()
+ } + } \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/CodeFile.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/CodeFile.cshtml new file mode 100644 index 000000000..404a2d58e --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/CodeFile.cshtml @@ -0,0 +1,11 @@ +@foreach (var u in Model.Usings) +{ +
using @(u);
+} + +@foreach (var ns in Model.Namespaces) +{ +
@ns.GenerateCode()
+ + +} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/DpProperty.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/DpProperty.cshtml new file mode 100644 index 000000000..aa0b57864 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/DpProperty.cshtml @@ -0,0 +1,8 @@ + @(Model.GetAttributesString()) + public @(Model.Type) @(Model.Name) + { + get { return (@(Model.Type))GetValue(@(Model.Name)Property); } + set { SetValue(@(Model.Name)Property, value); } + } + public static readonly DependencyProperty @(Model.Name)Property = + DependencyProperty.Register("@(Model.Name)", typeof(@(Model.Type)), typeof(@(Model.OwnerClass)), new PropertyMetadata(@(Model.DefaultValue) @(Model.PropertyChangedCallback != null ? ", " + Model.PropertyChangedCallback : ""))); \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/Method.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Method.cshtml new file mode 100644 index 000000000..3b54d4e57 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Method.cshtml @@ -0,0 +1,4 @@ +@(Model.GetModifierString()) @(Model.MethodModifier != CodeGenerator.MethodModifier.None ? Model.MethodModifier.ToString().ToLower() : null) @(Model.ReturnType) @(Model.Name)(@(Model.GetArgumentsString())) + { + @Model.Content + } \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/Namespace.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Namespace.cshtml new file mode 100644 index 000000000..05fd682c4 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Namespace.cshtml @@ -0,0 +1,7 @@ + namespace @(Model.Name) + { + @foreach (var cls in Model.Classes) + { +
@cls.GenerateCode()
+ } + } \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/Templates/Property.cshtml b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Property.cshtml new file mode 100644 index 000000000..f1dc61696 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/Templates/Property.cshtml @@ -0,0 +1,41 @@ +@if (Model.SetterContent == null && Model.GetterContent == null) +{ +
+ @(Model.GetAttributesString()) + @(Model.GetModifierString()) @(Model.Type) @(Model.Name) { get; set; } +
+} +else if (Model.SetterContent != null && Model.GetterContent != null) +{ +
+ private @(Model.Type) @(Model.GetPrivateField()); + + @(Model.GetAttributesString()) + @(Model.GetModifierString()) @(Model.Type) @(Model.Name) + { + get + { + @(Model.GetterContent) + } + @(Model.SetterModifier != CodeGenerator.CodeObjectModifier.None ? Model.SetterModifier.ToString().ToLower() : "") set + { + @(Model.SetterContent) + } + } +
+} +else if (Model.GetterContent != null) +{ +
+ private @(Model.Type) @(Model.GetPrivateField()); + + @(Model.GetAttributesString()) + @(Model.GetModifierString()) @(Model.Type) @(Model.Name) + { + get + { + @(Model.GetterContent) + } + } +
+} \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.CodeGeneration/packages.config b/Software/Visual_Studio/Tango.CodeGeneration/packages.config new file mode 100644 index 000000000..341d85750 --- /dev/null +++ b/Software/Visual_Studio/Tango.CodeGeneration/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file -- cgit v1.3.1