diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.CodeGeneration')
21 files changed, 989 insertions, 0 deletions
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 + { + /// <summary> + /// Gets or sets the class name. + /// </summary> + public String Name { get; set; } + + public List<String> InheritsFrom { get; set; } + + /// <summary> + /// Gets or sets the properties. + /// </summary> + public List<Property> Properties { get; set; } + + /// <summary> + /// Gets or sets the dependency properties. + /// </summary> + public List<DpProperty> DependencyProperties { get; set; } + + /// <summary> + /// Gets or sets the methods. + /// </summary> + public List<Method> Methods { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="Class"/> class. + /// </summary> + public Class() + : base() + { + Name = "Class1"; + Properties = new List<Property>(); + DependencyProperties = new List<DpProperty>(); + Methods = new List<Method>(); + InheritsFrom = new List<string>(); + } + + /// <summary> + /// Initializes a new instance of the <see cref="Class"/> class. + /// </summary> + /// <param name="name">The name.</param> + public Class(String name) + : this() + { + Name = name; + } + + /// <summary> + /// Initializes a new instance of the <see cref="Class"/> class. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="inheritsFrom">The inherits from.</param> + 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 +{ + /// <summary> + /// Represents a file code object. + /// </summary> + /// <seealso cref="Tango.CodeGeneration.CodeObject" /> + public class CodeFile : CodeObject + { + /// <summary> + /// Gets or sets the namespaces. + /// </summary> + public List<Namespace> Namespaces { get; set; } + + /// <summary> + /// Gets or sets the using section. + /// </summary> + public List<String> Usings { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="CodeFile"/> class. + /// </summary> + public CodeFile() : base() + { + Namespaces = new List<Namespace>(); + Usings = new List<string>(); + } + } +} 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 +{ + /// <summary> + /// Represents a code object base class. + /// </summary> + /// <seealso cref="Tango.CodeGeneration.ICodeObject" /> + public abstract class CodeObject : ICodeObject + { + /// <summary> + /// Initializes a new instance of the <see cref="CodeObject"/> class. + /// </summary> + public CodeObject() + { + Attributes = new List<string>(); + IndentResult = true; + } + + /// <summary> + /// Gets or sets the code object modifier. + /// </summary> + public CodeObjectModifier Modifier { get; set; } + + /// <summary> + /// Gets or sets the attributes associated with this code object. + /// </summary> + public List<String> Attributes { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether to indent the resulting code. + /// </summary> + public bool IndentResult { get; set; } + + /// <summary> + /// Generates the code represented by this code object. + /// </summary> + /// <returns></returns> + public virtual string GenerateCode() + { + var code = Helper.ParseTemplate(GetTemplate(), this); + + if (IndentResult) + { + code = Helper.IndentCSharpCode(code); + code = RemoveDoubleLines(code); + } + + code = code.Replace("&amp;quot;", "\""); + code = HttpUtility.HtmlDecode(code); + + return code; + } + + /// <summary> + /// Removes the double lines. + /// </summary> + /// <param name="str">The string.</param> + /// <returns></returns> + 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; + } + + /// <summary> + /// Gets the template associated with this code object. + /// </summary> + /// <returns></returns> + public virtual string GetTemplate() + { + return Helper.GetTemplate(this.GetType()); + } + + /// <summary> + /// Returns a <see cref="System.String" /> that represents this instance. + /// </summary> + /// <returns> + /// A <see cref="System.String" /> that represents this instance. + /// </returns> + public override string ToString() + { + return GenerateCode(); + } + + /// <summary> + /// Gets the modifier string. + /// </summary> + /// <returns></returns> + public String GetModifierString() + { + return Modifier.ToString().ToLower(); + } + + /// <summary> + /// Gets the attributes string. + /// </summary> + /// <returns></returns> + 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 +{ + /// <summary> + /// Represents a code object modifiers enumeration. + /// </summary> + public enum CodeObjectModifier + { + /// <summary> + /// Public modifier. + /// </summary> + Public, + /// <summary> + /// Internal modifier. + /// </summary> + Internal, + /// <summary> + /// Protected modifier. + /// </summary> + Protected, + /// <summary> + /// Private modifier. + /// </summary> + Private, + /// <summary> + /// No modifier. + /// </summary> + 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 +{ + /// <summary> + /// Represents a dependency property code object. + /// </summary> + /// <seealso cref="Tango.CodeGeneration.CodeObject" /> + public class DpProperty : CodeObject + { + /// <summary> + /// Gets or sets the property name. + /// </summary> + public String Name { get; set; } + + /// <summary> + /// Gets or sets the property type. + /// </summary> + public String Type { get; set; } + + /// <summary> + /// Gets or sets the default value. + /// </summary> + public String DefaultValue { get; set; } + + /// <summary> + /// Gets or sets the owner class. + /// </summary> + public String OwnerClass { get; set; } + + /// <summary> + /// Gets or sets the property changed callback. + /// </summary> + public String PropertyChangedCallback { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="DpProperty"/> class. + /// </summary> + public DpProperty() + : base() + { + Name = "MyProperty"; + Type = "int"; + } + + /// <summary> + /// Initializes a new instance of the <see cref="DpProperty"/> class. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="type">The type.</param> + /// <param name="defaultValue">The default value.</param> + /// <param name="ownerClass">The owner class.</param> + public DpProperty(String name, String type, String defaultValue, String ownerClass) + : this() + { + Name = name; + Type = type; + DefaultValue = defaultValue; + OwnerClass = ownerClass; + } + + /// <summary> + /// Initializes a new instance of the <see cref="DpProperty"/> class. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="type">The type.</param> + /// <param name="defaultValue">The default value.</param> + /// <param name="ownerClass">The owner class.</param> + /// <param name="propertyChangedCallback">The property changed callback.</param> + 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 + { + /// <summary> + /// Gets a code template by the code object type. + /// </summary> + /// <param name="type">The type.</param> + /// <returns></returns> + public static String GetTemplate(Type type) + { + return GetTemplate(type.Name); + } + + /// <summary> + /// Gets a code template by name. + /// </summary> + /// <param name="name">The name.</param> + /// <returns></returns> + 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(); + } + } + + /// <summary> + /// Parses the template using Razor Engine. + /// </summary> + /// <param name="template">The template.</param> + /// <param name="model">The model.</param> + /// <returns></returns> + public static String ParseTemplate(String template, object model) + { + return Engine.Razor.RunCompile(template, Guid.NewGuid().ToString(), model.GetType(), model).Replace("<div>", "").Replace("</div>", ""); + } + + /// <summary> + /// Indents the c sharp code. + /// </summary> + /// <param name="code">The code.</param> + /// <returns></returns> + 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 +{ + /// <summary> + /// Represents a code object. + /// </summary> + public interface ICodeObject + { + /// <summary> + /// Generates the code represented by this code object. + /// </summary> + String GenerateCode(); + + /// <summary> + /// Gets the template associated with this code object. + /// </summary> + 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 +{ + /// <summary> + /// Represents a method code object. + /// </summary> + /// <seealso cref="Tango.CodeGeneration.CodeObject" /> + public class Method : CodeObject + { + /// <summary> + /// Gets or sets the method name. + /// </summary> + public String Name { get; set; } + + /// <summary> + /// Gets or sets the method arguments. + /// </summary> + public List<KeyValuePair<String, String>> Arguments { get; set; } + + /// <summary> + /// Gets or sets the method return type. + /// </summary> + public String ReturnType { get; set; } + + /// <summary> + /// Gets or sets the method modifier. + /// </summary> + public MethodModifier MethodModifier { get; set; } + + /// <summary> + /// Gets or sets the method content. + /// </summary> + public String Content { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="Method"/> class. + /// </summary> + public Method() + : base() + { + Name = "MyMethod"; + Arguments = new List<KeyValuePair<string, string>>(); + ReturnType = "void"; + } + + /// <summary> + /// Initializes a new instance of the <see cref="Method"/> class. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="returnType">Type of the return.</param> + /// <param name="content">The content.</param> + /// <param name="methodModifier">The method modifier.</param> + public Method(String name, String returnType, String content, MethodModifier methodModifier = Tango.CodeGeneration.MethodModifier.None) + : this() + { + Name = name; + ReturnType = returnType; + Content = content; + MethodModifier = methodModifier; + } + + /// <summary> + /// Gets the arguments string. + /// </summary> + /// <returns></returns> + 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 +{ + /// <summary> + /// Represents a method modifier enumeration. + /// </summary> + 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 +{ + /// <summary> + /// Represents a namespace code object. + /// </summary> + /// <seealso cref="Tango.CodeGeneration.CodeObject" /> + public class Namespace : CodeObject + { + /// <summary> + /// Gets or sets the namespace name. + /// </summary> + public String Name { get; set; } + + /// <summary> + /// Gets or sets the classes section. + /// </summary> + public List<Class> Classes { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="Namespace"/> class. + /// </summary> + public Namespace() + : base() + { + Classes = new List<Class>(); + Modifier = CodeObjectModifier.None; + } + + /// <summary> + /// Initializes a new instance of the <see cref="Namespace"/> class. + /// </summary> + /// <param name="name">The name.</param> + 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 +{ + /// <summary> + /// Represents a property code object. + /// </summary> + /// <seealso cref="Tango.CodeGeneration.CodeObject" /> + public class Property : CodeObject + { + /// <summary> + /// Gets or sets the property name. + /// </summary> + public String Name { get; set; } + + /// <summary> + /// Gets or sets the property type. + /// </summary> + public String Type { get; set; } + + /// <summary> + /// Gets or sets the property setter modifier. + /// </summary> + public CodeObjectModifier SetterModifier { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether this property has a setter. + /// </summary> + public bool HasSetter { get; set; } + + /// <summary> + /// Gets or sets the content of the setter. + /// </summary> + public String SetterContent { get; set; } + + /// <summary> + /// Gets or sets the content of the getter. + /// </summary> + public String GetterContent { get; set; } + + /// <summary> + /// Gets the private field. + /// </summary> + /// <returns></returns> + public virtual String GetPrivateField() + { + return "_" + Name.ToLower(); + } + + /// <summary> + /// Initializes a new instance of the <see cref="Property"/> class. + /// </summary> + public Property() + : base() + { + Name = "MyProperty"; + Type = "int"; + SetterModifier = CodeObjectModifier.None; + } + + /// <summary> + /// Initializes a new instance of the <see cref="Property"/> class. + /// </summary> + /// <param name="name">The name.</param> + /// <param name="type">The type.</param> + 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{CAEDAE94-11ED-473C-888A-268A6D38CD20}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Tango.CodeGeneration</RootNamespace> + <AssemblyName>Tango.CodeGeneration</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <SccProjectName>SAK</SccProjectName> + <SccLocalPath>SAK</SccLocalPath> + <SccAuxPath>SAK</SccAuxPath> + <SccProvider>SAK</SccProvider> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\Build\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup> + <SignAssembly>false</SignAssembly> + </PropertyGroup> + <PropertyGroup> + <AssemblyOriginatorKeyFile> + </AssemblyOriginatorKeyFile> + </PropertyGroup> + <ItemGroup> + <Reference Include="RazorEngine, Version=3.10.0.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a, processorArchitecture=MSIL"> + <HintPath>..\packages\RazorEngine.3.10.0\lib\net45\RazorEngine.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Web" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="..\Versioning\GlobalVersionInfo.cs"> + <Link>GlobalVersionInfo.cs</Link> + </Compile> + <Compile Include="Class.cs" /> + <Compile Include="CodeFile.cs" /> + <Compile Include="CodeObject.cs" /> + <Compile Include="DpProperty.cs" /> + <Compile Include="FilterGLCodeFile.cs" /> + <Compile Include="Helper.cs" /> + <Compile Include="ICodeObject.cs" /> + <Compile Include="Method.cs" /> + <Compile Include="CodeObjectModifier.cs" /> + <Compile Include="MethodModifier.cs" /> + <Compile Include="Namespace.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Property.cs" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Templates\CodeFile.cshtml" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Templates\Property.cshtml" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Templates\DpProperty.cshtml" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Templates\Method.cshtml" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Templates\Class.cshtml" /> + </ItemGroup> + <ItemGroup> + <None Include="packages.config" /> + <EmbeddedResource Include="Templates\Namespace.cshtml" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project>
\ 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) + { + <div>@prop.GenerateCode()</div> + } + + @foreach (var dp in Model.DependencyProperties) + { + <div>@dp.GenerateCode()</div> + } + + @foreach (var method in Model.Methods) + { + <div>@method.GenerateCode()</div> + } + }
\ 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) +{ + <div>using @(u);</div> +} + +@foreach (var ns in Model.Namespaces) +{ + <div>@ns.GenerateCode()</div> + + +}
\ 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) + { + <div>@cls.GenerateCode()</div> + } + }
\ 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) +{ + <div> + @(Model.GetAttributesString()) + @(Model.GetModifierString()) @(Model.Type) @(Model.Name) { get; set; } + </div> +} +else if (Model.SetterContent != null && Model.GetterContent != null) +{ + <div> + 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) + } + } + </div> +} +else if (Model.GetterContent != null) +{ + <div> + private @(Model.Type) @(Model.GetPrivateField()); + + @(Model.GetAttributesString()) + @(Model.GetModifierString()) @(Model.Type) @(Model.Name) + { + get + { + @(Model.GetterContent) + } + } + </div> +}
\ 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Microsoft.AspNet.Razor" version="3.0.0" targetFramework="net45" /> + <package id="RazorEngine" version="3.10.0" targetFramework="net45" /> +</packages>
\ No newline at end of file |
