├── .gitignore
├── .nuget
├── NuGet.Config
├── NuGet.exe
└── NuGet.targets
├── README.md
├── T4TS.Attributes
├── Properties
│ └── AssemblyInfo.cs
├── T4TS.Attributes.csproj
├── TypeScriptInterfaceAttribute.cs
└── TypeScriptMemberAttribute.cs
├── T4TS.Build.Builder
├── BuildTemplate.csproj
├── BuildTemplateTask.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── README.md
├── SourceFileMerger.cs
├── SourceFileVisitor.cs
├── T4TS.Build.Builder.csproj
├── TemplateBuilder.cs
└── packages.config
├── T4TS.Build.sln
├── T4TS.Build
├── Properties
│ └── AssemblyInfo.cs
├── README.md
└── T4TS.Build.csproj
├── T4TS.Example.Models
├── ModelFromDifferentProject.cs
├── Properties
│ └── AssemblyInfo.cs
└── T4TS.Example.Models.csproj
├── T4TS.Example
├── Models
│ ├── Barfoo.cs
│ ├── ExtendsExplicit.cs
│ ├── Foobar.cs
│ ├── InheritanceTest1.cs
│ ├── InheritanceTest2.cs
│ ├── InheritanceTest3.cs
│ ├── InheritanceTest4.cs
│ ├── InheritanceTestExternal.cs
│ ├── Inherited.cs
│ ├── InheritsPartialModelByEF.cs
│ ├── Partial.First.cs
│ ├── Partial.Second.cs
│ └── TestClass.cs
├── Properties
│ └── AssemblyInfo.cs
├── Scripts
│ ├── App
│ │ ├── Existent External Module.d.ts
│ │ └── Test.ts
│ └── lib
│ │ └── jquery-1.8.d.ts
├── T4TS.Example.csproj
├── T4TS.d.ts
├── T4TS.tt
└── T4TS.tt.settings.t4
├── T4TS.Tests
├── CodeTraverserTests.cs
├── Fixtures
│ ├── Basic
│ │ ├── BasicModel.cs
│ │ └── Test.cs
│ ├── Dictionary
│ │ ├── DictionaryModel.cs
│ │ └── Test.cs
│ ├── Enumerable
│ │ ├── EnumerableModel.cs
│ │ └── Test.cs
│ ├── ExtendsExplicit
│ │ ├── ExtendsExplicit.cs
│ │ └── Test.cs
│ ├── ExternalProp
│ │ ├── ExternalPropModel.cs
│ │ └── Test.cs
│ ├── Indexed
│ │ ├── IndexedModel.cs
│ │ └── Test.cs
│ ├── Inheritance
│ │ ├── InheritanceModel.cs
│ │ └── Test.cs
│ ├── Nullable
│ │ ├── NullableModel.cs
│ │ └── Test.cs
│ ├── Options
│ │ ├── Default
│ │ │ ├── DefaultCamelCaseMemberNamesModel.cs
│ │ │ ├── DefaultCamelCaseMemberNamesTest.cs
│ │ │ ├── DefaultInterfaceNamePrefixModel.cs
│ │ │ ├── DefaultInterfaceNamePrefixTest.cs
│ │ │ ├── DefaultModuleModels.cs
│ │ │ ├── DefaultModuleTest.cs
│ │ │ ├── DefaultOptionalModels.cs
│ │ │ ├── DefaultOptionalTest.cs
│ │ │ ├── UseNativeDatesModel.cs
│ │ │ └── UseNativeDatesTest.cs
│ │ └── Override
│ │ │ ├── OverrideModels.cs
│ │ │ └── OverrideTests.cs
│ └── Partial
│ │ ├── PartialModel.cs
│ │ └── Test.cs
├── Models
│ ├── LocalModel.cs
│ └── ReservedPropModel.cs
├── Output
│ ├── MemberOutputAppenderTests.cs
│ └── ModuleOutputAppenderTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── T4TS.Tests.csproj
├── Traversal
│ ├── ClassTraversalTests.cs
│ ├── Models
│ │ ├── LocalModel.cs
│ │ └── ReservedPropModel.cs
│ ├── NamespaceTraverserTests.cs
│ └── ProjectTraversalTests.cs
├── TypeContext
│ └── TypeContextTests.cs
├── Utils
│ ├── DTETransformer.cs
│ └── OutputFor.cs
└── packages.config
├── T4TS.sln
├── T4TS
├── CodeTraverser.cs
├── Outputs
│ ├── InterfaceOutputAppender.cs
│ ├── MemberOutputAppender.cs
│ ├── ModuleOutputAppender.cs
│ ├── OutputAppender.cs
│ ├── OutputFormatter.cs
│ ├── TypeScriptInterface.cs
│ ├── TypeScriptInterfaceAttributeValues.cs
│ ├── TypeScriptInterfaceMember.cs
│ ├── TypeScriptMemberAttributeValues.cs
│ └── TypeScriptModule.cs
├── Properties
│ └── AssemblyInfo.cs
├── Settings.cs
├── T4TS.csproj
├── Traversal
│ ├── ClassTraverser.cs
│ ├── NamespaceTraverser.cs
│ ├── ProjectTraverser.cs
│ └── SolutionTraverser.cs
├── TypeContext.cs
├── TypeFullName.cs
├── TypeFullNameParser.cs
└── Types
│ ├── ArrayType.cs
│ ├── BoolType.cs
│ ├── DateTimeType.cs
│ ├── DictionaryType.cs
│ ├── GuidType.cs
│ ├── InterfaceType.cs
│ ├── NullableType.cs
│ ├── NumberType.cs
│ ├── StringType.cs
│ └── TypescriptType.cs
├── build
├── T4TS.Attributes.dll
├── T4TS.tt
└── T4TS.tt.settings.t4
├── license.txt
└── packages
└── repositories.config
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | obj/
3 | *.suo
4 | *.dll
5 | *.exe
6 | *.pdb
7 | *.csproj.user
8 | _ReSharper.T4TS.Example
9 | T4TS.Build/_ReSharper.T4TS.Build
10 | !buid/T4TS.Attributes.dll
11 | packages/
12 |
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cskeppstedt/t4ts/75f40033180d68ced0bfbbc7ae661c9b35bbc154/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 |
6 |
7 | false
8 |
9 |
10 | false
11 |
12 |
13 | true
14 |
15 |
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
31 |
32 |
33 |
34 |
35 | $(SolutionDir).nuget
36 |
37 |
38 |
39 | $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config
40 | $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config
41 |
42 |
43 |
44 | $(MSBuildProjectDirectory)\packages.config
45 | $(PackagesProjectConfig)
46 |
47 |
48 |
49 |
50 | $(NuGetToolsPath)\NuGet.exe
51 | @(PackageSource)
52 |
53 | "$(NuGetExePath)"
54 | mono --runtime=v4.0.30319 "$(NuGetExePath)"
55 |
56 | $(TargetDir.Trim('\\'))
57 |
58 | -RequireConsent
59 | -NonInteractive
60 |
61 | "$(SolutionDir) "
62 | "$(SolutionDir)"
63 |
64 |
65 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)
66 | $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols
67 |
68 |
69 |
70 | RestorePackages;
71 | $(BuildDependsOn);
72 |
73 |
74 |
75 |
76 | $(BuildDependsOn);
77 | BuildPackage;
78 |
79 |
80 |
81 |
82 |
83 |
84 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
99 |
100 |
103 |
104 |
105 |
106 |
108 |
109 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
141 |
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | T4TS (not worked on)
2 | ====
3 |
4 | This project is inactive
5 | ----
6 |
7 | I am no longer working on this project. Since it's been a long while since I was active on the .NET platform, I am unable to keep up with new versions of .NET to maintain the project. Thanks to all that have been contributing, it's been fun!
8 |
9 | Build status
10 | ----
11 | [](https://ci.appveyor.com/project/cskeppstedt/t4ts/branch/master)
12 |
13 | Usage
14 | ----
15 | 1. Install the NuGet package (https://nuget.org/packages/T4TS).
16 |
17 | 2. Decoreate any C# class that you want to generate an interface for, with the `TypeScriptInterfaceAttribute` (in the T4TS namespace).
18 |
19 | 3. Run the T4TS.tt-file (right-click and select *Run custom tool*).
20 |
21 | 4. The generated file T4TS.d.ts will now contain the interfaces that can be used in your TypeScript files.
22 |
23 | Examples
24 | ----
25 | C# classes:
26 | ```c#
27 | [TypeScriptInterface]
28 | public class MyModel
29 | {
30 | public int Number { get; set; }
31 | public string Name { get; set; }
32 | public ReferencedModel Ref { get; set; }
33 | }
34 |
35 | [TypeScriptInterface]
36 | public class ReferencedModel
37 | {
38 | public double Fraction { get; set; }
39 | public int[] Digits { get; set; }
40 | }
41 | ```
42 |
43 | Resulting T4TS.d.ts:
44 | ```javascript
45 | module T4TS {
46 | export interface MyModel {
47 | Number: number;
48 | Name: string;
49 | Ref: ReferencedModel;
50 | }
51 | export interface ReferencedModel {
52 | Fraction: number;
53 | Digits: number[];
54 | }
55 | }
56 | ```
57 |
58 | This interface can now be used in your TypeScript files:
59 |
60 | ```javascript
61 | ///
62 | class Test {
63 | constructor () {
64 | // Make an AJAX post and get some data from the server.
65 | // In the callback, you can specify that the data is of a certain type:
66 | $.post('./example', {}, (data: T4TS.MyModel) => {
67 | // Intellisense support for the properties:
68 | alert(data.Number.toString());
69 | alert(data.Ref.Digits[0].toString());
70 | });
71 | }
72 | }
73 | ```
74 |
75 | Specifications
76 | ----
77 | * Only public properties are considered
78 |
79 | * Right now, `System.DateTime` is considered a `string` in the type translation. The main reason is that the [JSON serialization in .NET MVC](http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format) will typically serialize a `DateTime` as `"\/Date(ticks)\/"`
80 |
81 | * The type translation works like this, from C# **=>** TypeScript, for each property:
82 | * Built-in numeric type (`int`, `double`, `float`, etc.) **=>** `number`
83 | * `string` **=>** `string`
84 | * `Nullable` **=>** `T?`
85 | * A class marked with `[TypeScriptInterface]` **=>** lookup the generated TypeScript name
86 | * Otherwise **=>** `any`
87 | * For `IEnumerable`, `Collection`, `List`, `IList` and `T[]` **=>** lookup type for `T` as above, and return `T[]`.
88 |
89 | * Inheritance of interfaces is supported. If `Bar` inherits `Foo` in C# and both are marked with the `TypeScriptInterfaceAttribute`, the generated interface would be `interface Bar extends Foo {...`.
90 |
91 | Customize the generated interfaces
92 | ----
93 | The attribute `TypeScriptInterfaceAttribute` is set on C# classes, and has the following properties:
94 |
95 | * **Name:** Specifies the name of the interface (default is the class name).
96 | * **Module:** Specifies the module of the interface (default _T4TS_).
97 | * **NamePrefix:** If specified, the interface name will be prefixed with this string.
98 |
99 | The attribute `TypeScriptMemberAttribute` can be set on the properties of a C# class, and has the following properties:
100 |
101 | * **Name:** Specifies the name of the member (default is the property name).
102 | * **Optional:** Specifies whether this member should be optional, ie. `member?: type` instead of `member: type`.
103 | * **Type:** Specifies the type of the member (default is to do type translation of the property).
104 | * **CamelCase:** If set to true, the first character of the member name will be lower cased.
105 | * **Ignore:** If set to true, the property will be ignored.
106 |
107 | Default settings
108 | ----
109 | There are a couple of default settings that can be specified in the `T4TS.tt.settings.t4` file.
110 |
111 | * **DefaultModule:** The default module name of an interfaces (if not specified by `TypeScriptInterfaceAttribute`). Default is `"T4TS"`.
112 | * **DefaultOptional:** The default value for the `Optional` flag for `TypeScriptMemberAttribute`. Default is `false`.
113 | * **DefaultCamelCaseMemberNames:** The default value for the `CamelCase` flag for `TypeScriptMemberAttribute`. Default is `false`.
114 | * **DefaultInterfaceNamePrefix:** The default value for the `NamePrefix` flag for `TypeScriptInterfaceAttribute`. Default is `""`.
115 | * **CompatibilityVersion:** The version of Typescript that is targeted. This will help handling breaking changes in the language grammar and/or compiler. Default (right now) is _0.9.1.1_.
116 |
117 | Known problems
118 | ----
119 | **TextTransformation fails:**
120 |
121 | I have experienced some error message the first time the T4TS package is installed via NuGet. However, if you build the project, or run the .tt-file, the error message disappears.
122 |
123 | Building
124 | ----
125 | See README.md in T4TS.Build and T4TS.Build.Builder for details.
126 |
127 | License
128 | ----
129 | [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
130 |
131 | Thanks to [T4MVC](http://t4mvc.codeplex.com/), which has been the inspiration. I also learned how to use the .tt-stuff from reading the source, and using part of the source code from T4MVC.
132 |
133 |
--------------------------------------------------------------------------------
/T4TS.Attributes/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Attributes")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Attributes")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("b31f4cfe-d412-4273-9dd4-46672802145d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS.Attributes/T4TS.Attributes.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {AF50A5E0-791D-47D4-91FE-56A7CE4577EB}
8 | Library
9 | Properties
10 | T4TS.Attributes
11 | T4TS.Attributes
12 | v2.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
51 |
--------------------------------------------------------------------------------
/T4TS.Attributes/TypeScriptInterfaceAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace T4TS
4 | {
5 | ///
6 | /// Add this attribute to a class to generate a corresponding TypeScript interface.
7 | ///
8 | [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
9 | public class TypeScriptInterfaceAttribute: Attribute
10 | {
11 | ///
12 | /// Specifies which module the interface should be placed.
13 | /// The default module will be used if not specified.
14 | ///
15 | public string Module { get; set; }
16 |
17 | ///
18 | /// The name of the interface.
19 | /// If not specified, the name of the class will be used.
20 | ///
21 | public string Name { get; set; }
22 |
23 | ///
24 | /// If specified, the interface name will be prefixed with this string.
25 | ///
26 | public string NamePrefix { get; set; }
27 |
28 | ///
29 | /// If specified, this interface will be extended by a external type that
30 | /// is part of another framework and does not require the existent module and
31 | /// type to be generated.
32 | ///
33 | public string Extends { get; set; }
34 |
35 | }
36 | }
--------------------------------------------------------------------------------
/T4TS.Attributes/TypeScriptMemberAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace T4TS
4 | {
5 | ///
6 | /// Add this attribute to a property to customize the generated interface member
7 | ///
8 | [AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
9 | public class TypeScriptMemberAttribute: Attribute
10 | {
11 | ///
12 | /// The member name in the interface.
13 | /// If not specified, the property name will be used.
14 | ///
15 | public string Name { get; set; }
16 |
17 | ///
18 | /// Specify if the member should be optional, ie. "name?: type".
19 | /// If not specified, the default value will be used (see settings).
20 | ///
21 | public bool Optional { get; set; }
22 |
23 | ///
24 | /// Specify which type the interface member will have.
25 | /// If not specified, a suitable type will be determined.
26 | ///
27 | public string Type { get; set; }
28 |
29 | ///
30 | /// If set to true, the first character of the member name will be lower cased.
31 | /// If not specified, the default value will be used (see settings).
32 | ///
33 | public bool CamelCase { get; set; }
34 |
35 | ///
36 | /// If set to true, this property will be ignored.
37 | ///
38 | public bool Ignore { get; set; }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/BuildTemplate.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 | Release
12 | ..\build
13 |
14 |
15 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
33 |
34 |
35 |
36 |
42 |
43 |
44 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
66 |
67 |
68 |
69 |
70 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/BuildTemplateTask.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Build.Framework;
2 | using Microsoft.Build.Utilities;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using T4TS.Build.Builder.Properties;
6 |
7 | namespace T4TS.Build.Builder
8 | {
9 | public class BuildTemplateTask : Task
10 | {
11 | ///
12 | /// The source files to merge and build the T4 template from.
13 | ///
14 | [Required]
15 | public ITaskItem[] SourceFiles { get; set; }
16 |
17 | ///
18 | /// The output dir to save T4TS.tt (and settings file) to. Defaults to "{T4TSBasePath}\build".
19 | ///
20 | public ITaskItem OutputDir { get; set; }
21 |
22 | ///
23 | /// The base directory of the T4TS project. Should be "..\" relatively from this project.
24 | /// Defaults to "..\".
25 | ///
26 | public ITaskItem T4TSBasePath { get; set; }
27 |
28 | ///
29 | /// This will be set to the full path of the generated T4TS.tt when the Task has completed.
30 | ///
31 | [Output]
32 | public ITaskItem TemplateOutputFile { get; set; }
33 |
34 | public override bool Execute()
35 | {
36 | var basePath = GetBasePath();
37 |
38 | var sourceFileInfos = new List();
39 | foreach (var sourceFile in SourceFiles)
40 | {
41 | string path = Path.Combine(basePath.FullName, "T4TS", sourceFile.ItemSpec);
42 | sourceFileInfos.Add(new FileInfo(path));
43 | }
44 |
45 | this.Log.LogMessage("Building template from {0} files:", sourceFileInfos.Count);
46 | foreach (var fi in sourceFileInfos)
47 | this.Log.LogMessage(" - " + fi.FullName);
48 |
49 | var t4tsContent = TemplateBuilder.BuildT4TSFromSourceFiles(sourceFileInfos);
50 |
51 | var outputDir = GetOutputDir();
52 |
53 | var t4tsFile = new FileInfo(Path.Combine(outputDir.FullName, "T4TS.tt"));
54 | File.WriteAllText(t4tsFile.FullName, t4tsContent);
55 | LogFileWrite(t4tsFile);
56 |
57 | var templateSettingsFile = new FileInfo(Path.Combine(outputDir.FullName, "T4TS.tt.settings.t4"));
58 | File.WriteAllText(templateSettingsFile.FullName, Resources.TemplateSettings);
59 | LogFileWrite(templateSettingsFile);
60 |
61 | TemplateOutputFile = new TaskItem(t4tsFile.FullName);
62 | return true;
63 | }
64 |
65 | void LogFileWrite(FileInfo fileInfo)
66 | {
67 | this.Log.LogMessage("{0} written to file ({1} bytes): {2}", fileInfo.Name, fileInfo.Length, fileInfo.FullName);
68 | }
69 |
70 | DirectoryInfo GetBasePath()
71 | {
72 | if (T4TSBasePath == null)
73 | return new DirectoryInfo(@"..\");
74 |
75 | return new DirectoryInfo(T4TSBasePath.ItemSpec);
76 | }
77 |
78 | DirectoryInfo GetOutputDir()
79 | {
80 | if (OutputDir == null)
81 | return new DirectoryInfo(Path.Combine(GetBasePath().FullName, "build"));
82 |
83 | return new DirectoryInfo(OutputDir.ItemSpec);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Build.Builder")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Build.Builder")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("346f3511-1c1b-4b77-930e-6f3c3a0dd09d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.18444
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace T4TS.Build.Builder.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("T4TS.Build.Builder.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to <#@ template language="C#" debug="true" hostspecific="true" #>
65 | ///<#@ output extension=".d.ts" #>
66 | ///<#@ assembly name="System.Core" #>
67 | ///<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
68 | ///<#@ assembly name="EnvDTE" #>
69 | ///<#@ assembly name="EnvDTE80" #>
70 | ///<#@ import namespace="System.Collections.Generic" #>
71 | ///<#@ import namespace="System.Linq" #>
72 | ///<#@ import namespace="System.Text" #>
73 | ///<#@ import namespace="EnvDTE" #>
74 | ///<#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
75 | ///<#@ import namespace [rest of string was truncated]";.
76 | ///
77 | internal static string TemplatePrefix {
78 | get {
79 | return ResourceManager.GetString("TemplatePrefix", resourceCulture);
80 | }
81 | }
82 |
83 | ///
84 | /// Looks up a localized string similar to <#+
85 | ////// <summary>
86 | ////// These settings can be used to customize the output of T4TS.
87 | ////// The default for all settings are determined by T4TS.tt in ReadSettings().
88 | ////// </summary>
89 | ///readonly Dictionary<string, object> SettingsValues = new Dictionary<string, object>()
90 | ///{
91 | /// // The default module of the generated interface. If a module is
92 | /// // not specified by the TypeScriptInterfaceAttribute, the interface
93 | /// // will belong to this module (may be empty, in which case the
94 | /// // interface will be glo [rest of string was truncated]";.
95 | ///
96 | internal static string TemplateSettings {
97 | get {
98 | return ResourceManager.GetString("TemplateSettings", resourceCulture);
99 | }
100 | }
101 |
102 | ///
103 | /// Looks up a localized string similar to #>.
104 | ///
105 | internal static string TemplateSuffix {
106 | get {
107 | return ResourceManager.GetString("TemplateSuffix", resourceCulture);
108 | }
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | <#@ template language="C#" debug="true" hostspecific="true" #>
122 | <#@ output extension=".d.ts" #>
123 | <#@ assembly name="System.Core" #>
124 | <#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
125 | <#@ assembly name="EnvDTE" #>
126 | <#@ assembly name="EnvDTE80" #>
127 | <#@ import namespace="System.Collections.Generic" #>
128 | <#@ import namespace="System.Linq" #>
129 | <#@ import namespace="System.Text" #>
130 | <#@ import namespace="EnvDTE" #>
131 | <#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
132 | <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
133 | <#@ Include File="T4TS.tt.settings.t4" #><#=
134 | OutputFormatter.GetOutput(GetDataToRender(), GetSettings()) #><#+
135 |
136 | Settings settings = null;
137 | Settings GetSettings()
138 | {
139 | if (settings== null)
140 | settings = Settings.Parse(SettingsValues);
141 |
142 | return settings;
143 | }
144 |
145 | List<TypeScriptModule> GetDataToRender() {
146 | DTE dte = null;
147 |
148 | // Get the DTE service from the host
149 | var serviceProvider = Host as IServiceProvider;
150 | if (serviceProvider != null)
151 | dte = serviceProvider.GetService(typeof(SDTE)) as DTE;
152 |
153 | // Fail if we couldn't get the DTE. This can happen when trying to run in TextTransform.exe
154 | if (dte == null)
155 | throw new Exception("Can only execute through the Visual Studio host");
156 |
157 | var project = GetProjectContainingT4File(dte);
158 |
159 | if (project == null)
160 | throw new Exception("Could not find the VS project containing the T4TS file.");
161 |
162 | var generator = new CodeTraverser(dte.Solution, GetSettings());
163 | return generator.GetAllInterfaces().ToList();
164 | }
165 |
166 | Project GetProjectContainingT4File(DTE dte) {
167 |
168 | // Find the .tt file's ProjectItem
169 | ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
170 |
171 | // If the .tt file is not opened, open it
172 | if (projectItem.Document == null)
173 | projectItem.Open(Constants.vsViewKindCode);
174 |
175 | // Mark the .tt file as unsaved. This way it will be saved and update itself next time the
176 | // project is built. Basically, it keeps marking itself as unsaved to make the next build work.
177 | // Note: this is certainly hacky, but is the best I could come up with so far.
178 | projectItem.Document.Saved = false;
179 |
180 | return projectItem.ContainingProject;
181 | }
182 |
183 | The text to place in the beginning of T4TS.tt, before all code definitions.
184 |
185 |
186 | <#+
187 | /// <summary>
188 | /// These settings can be used to customize the output of T4TS.
189 | /// The default for all settings are determined by T4TS.tt in ReadSettings().
190 | /// </summary>
191 | readonly Dictionary<string, object> SettingsValues = new Dictionary<string, object>()
192 | {
193 | // The default module of the generated interface. If a module is
194 | // not specified by the TypeScriptInterfaceAttribute, the interface
195 | // will belong to this module (may be empty, in which case the
196 | // interface will be globally accessible).
197 | // Type: string, defaults to "T4TS" if not specified.
198 | { "DefaultModule", null },
199 |
200 | // The default value for the Optional flag for an interface member.
201 | // If not specified by the TypeScriptInterfaceAttribute, the Optional
202 | // flag will be set to this value. If the Optional flag is true, the
203 | // generated member will look like "member?: type" instead of "member: type".
204 | // Type: bool?, defaults to false if not specified.
205 | { "DefaultOptional", null },
206 |
207 | // The default value for the CamelCase flag for an interface member name.
208 | // If set to true, the first character of member names will be lower cased.
209 | // Type: bool?, defaults to false if not specified.
210 | { "DefaultCamelCaseMemberNames", null },
211 |
212 | // The default string to prefix interface names with. For instance, you
213 | // might want to prefix the names with an "I" to get conventional
214 | // interface names.
215 | // Type: string, defaults to "" if not specified.
216 | { "DefaultInterfaceNamePrefix", null },
217 |
218 | // The version of Typescript that is targeted. This is required to handle
219 | // breaking changes in the language grammar and/or compiler.
220 | // Type: System.Version
221 | { "CompatibilityVersion", null },
222 |
223 | // The default value for DateTime type translation.
224 | // Type: bool?, defaults to false if not specified.
225 | { "UseNativeDates", null }
226 | };
227 | #>
228 | The contents of the generated template settings file T4TS.tt.settings.t4
229 |
230 |
231 | #>
232 | The text to place after all the code definition.
233 |
234 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/README.md:
--------------------------------------------------------------------------------
1 | T4TS.Build.Builder
2 | ==================
3 |
4 | This project contains the `BuildTemplateTask` which is used to
5 | generate the `T4TS.tt` template file.
6 |
7 | Building with MSBuild
8 | ---------------------
9 |
10 | The build is fully automated through MSBuild. You can run this command
11 | in a console to build T4TS.tt, assuming that you are standing in
12 | `.\T4TS.Build.Builder\`:
13 |
14 | `MSBuild.exe BuildTemplate.csproj`
15 |
16 | If you don't have MSBuild in your path, you will have to specify the path:
17 |
18 | `c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe BuildTemplate.csproj`
19 |
20 | How T4TS.tt is built
21 | --------------------
22 |
23 | T4TS.tt is built by parsing all C# classes found in `..\T4TS\T4TS.csproj`,
24 | which are merged into a single string. This is then combined with two
25 | strings found in `Properties\Resources.resx`:
26 |
27 | * `TemplatePrefix`
28 | * `TemplateSuffix`
29 |
30 | `T4TS.tt` is written to the directory `OutputDir` which is passed as an argument
31 | to the `BuildTemplateTask` (see `BuildTemplate.csproj`).
32 |
33 | How T4TS.tt.settings.t4 is built
34 | --------------------------------
35 |
36 | `T4TS.tt.settings.t4` is also written to the `OutputDir` directory. Its
37 | content is simply the `TemplateSettings` string found in `Properties\Resources.resx`.
38 |
39 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/SourceFileMerger.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace T4TS.Build.Builder
8 | {
9 | class SourceFileMerger
10 | {
11 | static readonly SourceFileVisitor Visitor = new SourceFileVisitor();
12 |
13 | ///
14 | /// Merges all the source files (they are assumed to be C# files).
15 | ///
16 | /// A string with all C# classes found in the source files.
17 | public string MergeSourceFileClasses(IEnumerable files)
18 | {
19 | Visitor.Clear();
20 |
21 | foreach (var file in files)
22 | VisitFile(file);
23 |
24 | var sb = new StringBuilder();
25 | sb.AppendLine();
26 |
27 | foreach (string classDefinition in Visitor.Classes)
28 | {
29 | // Indentation is important!
30 | sb.Append(" ");
31 | sb.AppendLine(classDefinition);
32 | sb.AppendLine();
33 | }
34 |
35 | return sb.ToString();
36 | }
37 |
38 | void VisitFile(FileInfo file)
39 | {
40 | using (var sr = new StreamReader(file.OpenRead()))
41 | {
42 | var syntaxTree = CSharpSyntaxTree.ParseText(sr.ReadToEnd());
43 | var root = (CompilationUnitSyntax)syntaxTree.GetRoot();
44 |
45 | foreach (var child in root.ChildNodes())
46 | VisitNode(child as CSharpSyntaxNode);
47 | }
48 | }
49 |
50 | void VisitNode(CSharpSyntaxNode node)
51 | {
52 | if (node == null)
53 | return;
54 |
55 | node.Accept(Visitor);
56 |
57 | var children = node.ChildNodes();
58 | if (children != null)
59 | {
60 | foreach (var child in children)
61 | VisitNode(child as CSharpSyntaxNode);
62 | }
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/SourceFileVisitor.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System.Collections.Generic;
4 |
5 | namespace T4TS.Build.Builder
6 | {
7 | class SourceFileVisitor: CSharpSyntaxVisitor
8 | {
9 | public readonly List Classes = new List();
10 |
11 | public override void VisitClassDeclaration(ClassDeclarationSyntax node)
12 | {
13 | Classes.Add(node.ToString());
14 | }
15 |
16 | public void Clear()
17 | {
18 | Classes.Clear();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/T4TS.Build.Builder.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {48257228-AF75-467E-B881-F10ECB0C2749}
8 | Library
9 | Properties
10 | T4TS.Build.Builder
11 | T4TS.Build.Builder
12 | v4.5
13 | 512
14 |
15 | publish\
16 | true
17 | Disk
18 | false
19 | Foreground
20 | 7
21 | Days
22 | false
23 | false
24 | true
25 | 0
26 | 1.0.0.%2a
27 | false
28 | false
29 | true
30 | ..\
31 | true
32 |
33 |
34 | AnyCPU
35 | true
36 | full
37 | false
38 | bin\Debug\
39 | DEBUG;TRACE
40 | prompt
41 | 4
42 | false
43 |
44 |
45 | AnyCPU
46 | pdbonly
47 | true
48 | bin\Release\
49 | TRACE
50 | prompt
51 | 4
52 | false
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 | ..\packages\Microsoft.CodeAnalysis.Common.0.7.4052301-beta\lib\net45\Microsoft.CodeAnalysis.dll
62 |
63 |
64 | ..\packages\Microsoft.CodeAnalysis.CSharp.0.7.4052301-beta\lib\net45\Microsoft.CodeAnalysis.CSharp.dll
65 |
66 |
67 |
68 | ..\packages\Microsoft.Bcl.Immutable.1.1.20-beta\lib\portable-net45+win8\System.Collections.Immutable.dll
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | True
82 | True
83 | Resources.resx
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | Designer
92 |
93 |
94 |
95 |
96 |
97 | ResXFileCodeGenerator
98 | Resources.Designer.cs
99 |
100 |
101 |
102 |
103 | False
104 | Microsoft .NET Framework 4.5 %28x86 and x64%29
105 | true
106 |
107 |
108 | False
109 | .NET Framework 3.5 SP1 Client Profile
110 | false
111 |
112 |
113 | False
114 | .NET Framework 3.5 SP1
115 | false
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
126 |
127 |
128 |
129 |
136 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/TemplateBuilder.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using T4TS.Build.Builder.Properties;
4 |
5 | namespace T4TS.Build.Builder
6 | {
7 | class TemplateBuilder
8 | {
9 | ///
10 | /// Combines the template prefix, the class definitions, and the template suffix into
11 | /// the complete contents of T4TS.tt.
12 | ///
13 | public static string BuildT4TSFromSourceFiles(IEnumerable fromFiles)
14 | {
15 | var merger = new SourceFileMerger();
16 | string combinedSource = merger.MergeSourceFileClasses(fromFiles);
17 | string template = Resources.TemplatePrefix + combinedSource + Resources.TemplateSuffix;
18 |
19 | return template;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/T4TS.Build.Builder/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/T4TS.Build.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Build", "T4TS.Build\T4TS.Build.csproj", "{DD5BD892-D179-4E30-9185-9475BBF18B1F}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Example.Models", "T4TS.Example.Models\T4TS.Example.Models.csproj", "{93EE0391-DB26-40CC-A613-6CA32E3EEB18}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Build.Builder", "T4TS.Build.Builder\T4TS.Build.Builder.csproj", "{48257228-AF75-467E-B881-F10ECB0C2749}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{597D4C27-5BF8-43CB-A355-837F7DA741B1}"
11 | ProjectSection(SolutionItems) = preProject
12 | .nuget\NuGet.Config = .nuget\NuGet.Config
13 | .nuget\NuGet.exe = .nuget\NuGet.exe
14 | .nuget\NuGet.targets = .nuget\NuGet.targets
15 | EndProjectSection
16 | EndProject
17 | Global
18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
19 | Debug|Any CPU = Debug|Any CPU
20 | Release|Any CPU = Release|Any CPU
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {DD5BD892-D179-4E30-9185-9475BBF18B1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {DD5BD892-D179-4E30-9185-9475BBF18B1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {DD5BD892-D179-4E30-9185-9475BBF18B1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
26 | {DD5BD892-D179-4E30-9185-9475BBF18B1F}.Release|Any CPU.Build.0 = Release|Any CPU
27 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Debug|Any CPU.Build.0 = Debug|Any CPU
29 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
30 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Release|Any CPU.Build.0 = Release|Any CPU
31 | {48257228-AF75-467E-B881-F10ECB0C2749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32 | {48257228-AF75-467E-B881-F10ECB0C2749}.Debug|Any CPU.Build.0 = Debug|Any CPU
33 | {48257228-AF75-467E-B881-F10ECB0C2749}.Release|Any CPU.ActiveCfg = Release|Any CPU
34 | {48257228-AF75-467E-B881-F10ECB0C2749}.Release|Any CPU.Build.0 = Release|Any CPU
35 | EndGlobalSection
36 | GlobalSection(SolutionProperties) = preSolution
37 | HideSolutionNode = FALSE
38 | EndGlobalSection
39 | EndGlobal
40 |
--------------------------------------------------------------------------------
/T4TS.Build/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Build")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Build")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("613f9be5-eae7-4b65-b505-4fa7b3e6a45c")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS.Build/README.md:
--------------------------------------------------------------------------------
1 | T4TS.Build
2 | ==========
3 |
4 | This project shows how a merged, and ready-for-deploy, T4TS.tt file works in a project.
5 |
6 | T4TS.Build.csproj has a `` which triggers
7 | `T4TS.Build.Builder\BuildTemplate.csproj` to build. See `T4TS.Build.Builder\README.md`
8 | for details. This will result in 3 files in the `build\` directory:
9 |
10 | * T4TS.Attributes.dll
11 | * T4TS.tt
12 | * T4TS.tt.settings.t4
13 |
14 | As you might've noticed, these files are linked to this project.
--------------------------------------------------------------------------------
/T4TS.Build/T4TS.Build.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {DD5BD892-D179-4E30-9185-9475BBF18B1F}
8 | Library
9 | Properties
10 | T4TS.Build
11 | T4TS.Build
12 | v4.5
13 | 512
14 |
15 |
16 | AnyCPU
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | AnyCPU
27 | pdbonly
28 | true
29 | bin\Release\
30 | TRACE
31 | prompt
32 | 4
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | ..\build\T4TS.Attributes.dll
53 |
54 |
55 |
56 |
57 | Models\Barfoo.cs
58 |
59 |
60 | Models\Foobar.cs
61 |
62 |
63 | Models\InheritanceTest1.cs
64 |
65 |
66 | Models\InheritanceTest2.cs
67 |
68 |
69 | Models\InheritanceTest3.cs
70 |
71 |
72 | Models\InheritanceTest4.cs
73 |
74 |
75 | Models\InheritanceTestExternal.cs
76 |
77 |
78 | Models\Inherited.cs
79 |
80 |
81 | Models\Partial.First.cs
82 |
83 |
84 | Models\Partial.Second.cs
85 |
86 |
87 | Models\TestClass.cs
88 |
89 |
90 |
91 |
92 |
93 | T4TS.tt
94 | TextTemplatingFileGenerator
95 | T4TS.d.ts
96 |
97 |
98 | T4TS.tt.settings.t4
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | {93ee0391-db26-40cc-a613-6ca32e3eeb18}
108 | T4TS.Example.Models
109 |
110 |
111 |
112 |
113 | T4TS.d.ts
114 | True
115 | True
116 | T4TS.tt
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/T4TS.Example.Models/ModelFromDifferentProject.cs:
--------------------------------------------------------------------------------
1 | namespace T4TS.Example.Models
2 | {
3 | [TypeScriptInterface(Module="External")]
4 | public class ModelFromDifferentProject
5 | {
6 | public int Id { get; set; }
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/T4TS.Example.Models/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Example.Models")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Example.Models")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("16455b48-fa42-4ba3-b73b-958b4eaec902")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS.Example.Models/T4TS.Example.Models.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}
8 | Library
9 | Properties
10 | T4TS.Example.Models
11 | T4TS.Example.Models
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | {AF50A5E0-791D-47D4-91FE-56A7CE4577EB}
48 | T4TS.Attributes
49 |
50 |
51 |
52 |
59 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/Barfoo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace T4TS.Example.Models
5 | {
6 | [TypeScriptInterface(Module = "")]
7 | public class Barfoo
8 | {
9 | public int Number { get; set; }
10 | public Inherited Complex { get; set; }
11 | public string Name { get; set; }
12 | public DateTime DateTime { get; set; }
13 | public Dictionary aValue { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/ExtendsExplicit.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace T4TS.Example.Models
5 | {
6 | [TypeScriptInterface(Name = "someEntity", Extends = "externalJSModule.Entity")]
7 | public class ExtendsExplicit
8 | {
9 | public int Number { get; set; }
10 | public string Name { get; set; }
11 | public DateTime DateTime { get; set; }
12 | public Dictionary aValue { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/Foobar.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace T4TS.Example.Models
5 | {
6 | [TypeScriptInterface(Module = "Fooz", NamePrefix = "I")]
7 | public class Foobar
8 | {
9 | [TypeScriptMember(Name = "OverrideAll", Optional = true, Type = "any")]
10 | public string SomeString { get; set; }
11 | public Guid AGuid { get; set; }
12 | public Foobar Recursive { get; set; }
13 | public int? NullableInt { get; set; }
14 | public double? NullableDouble { get; set; }
15 | public Barfoo[] NestedObjectArr { get; set; }
16 | public List NestedObjectList { get; set; }
17 | public string[][] TwoDimensions { get; set; }
18 | public Barfoo[][][] ThreeDimensions { get; set; }
19 |
20 | [TypeScriptMember(CamelCase=true)]
21 | public int CamelCasePlease { get; set; }
22 |
23 | [TypeScriptMember(Ignore = true)]
24 | public int IgnoreMe { get; set; }
25 |
26 | [TypeScriptMember(Ignore = false)]
27 | public int DoNotIgnoreMe { get; set; }
28 | }
29 | }
--------------------------------------------------------------------------------
/T4TS.Example/Models/InheritanceTest1.cs:
--------------------------------------------------------------------------------
1 | namespace T4TS.Example.Models
2 | {
3 | [TypeScriptInterface]
4 | public class InheritanceTest1 : Barfoo
5 | {
6 | public string SomeString { get; set; }
7 | public Foobar Recursive { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/T4TS.Example/Models/InheritanceTest2.cs:
--------------------------------------------------------------------------------
1 | namespace T4TS.Example.Models
2 | {
3 | [TypeScriptInterface]
4 | public class InheritanceTest2 : InheritanceTest1
5 | {
6 | public string SomeString2 { get; set; }
7 | public Foobar Recursive2 { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/T4TS.Example/Models/InheritanceTest3.cs:
--------------------------------------------------------------------------------
1 | namespace T4TS.Example.Models
2 | {
3 | [TypeScriptInterface]
4 | public class InheritanceTest3 : Inherited
5 | {
6 | public string SomeString3 { get; set; }
7 | public Foobar Recursive3 { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/T4TS.Example/Models/InheritanceTest4.cs:
--------------------------------------------------------------------------------
1 | namespace T4TS.Example.Models
2 | {
3 | [TypeScriptInterface]
4 | public class InheritanceTest4 : TestClass
5 | {
6 | public string SomeString4 { get; set; }
7 | public Foobar Recursive4 { get; set; }
8 | }
9 | }
--------------------------------------------------------------------------------
/T4TS.Example/Models/InheritanceTestExternal.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Example.Models
8 | {
9 | [TypeScriptInterface]
10 | public class InheritanceTestExternal : ModelFromDifferentProject
11 | {
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/Inherited.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 |
3 | namespace T4TS.Example.Models
4 | {
5 | [TypeScriptInterface(Name = "OverridenName")]
6 | public class Inherited : List
7 | {
8 | [TypeScriptMember(Optional = true, Name = "OtherName")]
9 | public string StringProperty { get; set; }
10 | public int[] Integers { get; set; }
11 | public List Doubles { get; set; }
12 | public List> TwoDimList { get; set; }
13 | }
14 | }
--------------------------------------------------------------------------------
/T4TS.Example/Models/InheritsPartialModelByEF.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Example.Models
8 | {
9 | ///
10 | /// assume this class was generated by EF; can't add (easily) TypeScriptInterface to the generated file
11 | ///
12 | public partial class PartialModelByEF
13 | {
14 | public int SomeId { get; set; }
15 | }
16 |
17 | ///
18 | /// This is just to add the TypeScriptInterface to the generated class
19 | ///
20 | [TypeScriptInterface]
21 | public partial class PartialModelByEF
22 | {
23 | //just to add TypeScriptInterface
24 | }
25 |
26 | ///
27 | /// And this is a DTO class with some more properties
28 | ///
29 | [TypeScriptInterface]
30 | public partial class InheritsPartialModelByEF : PartialModelByEF
31 | {
32 | public string NewProperty { get; set; }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/Partial.First.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace T4TS.Example.Models
4 | {
5 | partial class Partial
6 | {
7 | public string FromFirstClass { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/Partial.Second.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace T4TS.Example.Models
4 | {
5 | [TypeScriptInterface]
6 | partial class Partial
7 | {
8 | public string FromSecondClass { get; set; }
9 | public bool? AlsoSecondClass { get; set; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/T4TS.Example/Models/TestClass.cs:
--------------------------------------------------------------------------------
1 | namespace T4TS.Example.Models
2 | {
3 | public class TestClass
4 | {
5 | public string Property { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/T4TS.Example/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Example")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Example")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1653e180-4edd-4a43-9edb-887a51fe4d9a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS.Example/Scripts/App/Existent External Module.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | // this is a samle external module that may already exist
4 | // somewhere in the application
5 | declare module externalJSModule {
6 |
7 | interface Entity {
8 |
9 | }
10 |
11 | }
--------------------------------------------------------------------------------
/T4TS.Example/Scripts/App/Test.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | module App {
5 | export class Test {
6 | private partialClass: T4TS.Partial;
7 |
8 | constructor() {
9 |
10 | this.partialClass = {
11 | FromFirstClass: '',
12 | FromSecondClass: '',
13 | AlsoSecondClass: true
14 | };
15 |
16 | // Make an AJAX post and get some data from the server.
17 | // In the callback, you can specify that the data is of a certain type:
18 | $.post('./example', {}, (data: Fooz.IFoobar) => {
19 |
20 | // Intellisense support for the properties:
21 | alert(data.NestedObjectArr[0].Name);
22 | alert(data.Recursive.OverrideAll ? "1" : "0");
23 |
24 | // When using lib functions (such as $.each) you need to help
25 | // by explicitly typing the object in the callback:
26 | $.each(data.NestedObjectArr, (i, v: T4TS.InheritanceTest1) => {
27 | alert(v.SomeString);
28 | });
29 | });
30 | }
31 |
32 | }
33 | }
--------------------------------------------------------------------------------
/T4TS.Example/T4TS.Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {51E03259-D166-4DA9-8D55-1FA7BDE922ED}
8 | Library
9 | Properties
10 | T4TS.Example
11 | T4TS.Example
12 | v4.5
13 | 512
14 |
15 |
16 | true
17 | full
18 | false
19 | bin\Debug\
20 | DEBUG;TRACE
21 | prompt
22 | 4
23 |
24 |
25 | pdbonly
26 | true
27 | bin\Release\
28 | TRACE
29 | prompt
30 | 4
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | True
58 | True
59 | T4TS.tt
60 |
61 |
62 | TextTemplatingFileGenerator
63 | T4TS.d.ts
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | {af50a5e0-791d-47d4-91fe-56a7ce4577eb}
75 | T4TS.Attributes
76 |
77 |
78 | {93ee0391-db26-40cc-a613-6ca32e3eeb18}
79 | T4TS.Example.Models
80 |
81 |
82 | {2b9cfea6-586a-4e3b-8575-79447d5dc086}
83 | T4TS
84 |
85 |
86 |
87 |
88 |
89 |
90 |
97 |
--------------------------------------------------------------------------------
/T4TS.Example/T4TS.d.ts:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Generated by T4TS.tt - don't make any changes in this file
3 | ****************************************************************************/
4 |
5 | // -- Begin global interfaces
6 | /** Generated from T4TS.Example.Models.Barfoo **/
7 | interface Barfoo {
8 | Number: number;
9 | Complex: T4TS.OverridenName;
10 | Name: string;
11 | DateTime: string;
12 | aValue: { [name: string]: any};
13 | }
14 | // -- End global interfaces
15 |
16 | declare module External {
17 | /** Generated from T4TS.Example.Models.ModelFromDifferentProject **/
18 | export interface ModelFromDifferentProject {
19 | Id: number;
20 | }
21 | }
22 |
23 | declare module Fooz {
24 | /** Generated from T4TS.Example.Models.Foobar **/
25 | export interface IFoobar {
26 | OverrideAll?: any;
27 | AGuid: string;
28 | Recursive: Fooz.IFoobar;
29 | NullableInt: number;
30 | NullableDouble: number;
31 | NestedObjectArr: Barfoo[];
32 | NestedObjectList: Barfoo[];
33 | TwoDimensions: string[][];
34 | ThreeDimensions: Barfoo[][][];
35 | camelCasePlease: number;
36 | DoNotIgnoreMe: number;
37 | }
38 | }
39 |
40 | declare module Override {
41 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultModuleOverrideModel **/
42 | export interface DefaultModuleOverrideModel {
43 | SomeProp: string;
44 | }
45 | }
46 |
47 | declare module SomeModule {
48 | /** Generated from T4TS.Tests.Fixtures.Options.Override.ModuleNameOverrideModel **/
49 | export interface ModuleNameOverrideModel {
50 | SomeThirdProp: string;
51 | }
52 | }
53 |
54 | declare module T4TS {
55 | /** Generated from T4TS.Example.Models.ExtendsExplicit **/
56 | export interface someEntity extends externalJSModule.Entity {
57 | Number: number;
58 | Name: string;
59 | DateTime: string;
60 | aValue: { [name: string]: any};
61 | }
62 | /** Generated from T4TS.Example.Models.InheritanceTest1 **/
63 | export interface InheritanceTest1 extends Barfoo {
64 | SomeString: string;
65 | Recursive: Fooz.IFoobar;
66 | }
67 | /** Generated from T4TS.Example.Models.InheritanceTest2 **/
68 | export interface InheritanceTest2 extends T4TS.InheritanceTest1 {
69 | SomeString2: string;
70 | Recursive2: Fooz.IFoobar;
71 | }
72 | /** Generated from T4TS.Example.Models.InheritanceTest3 **/
73 | export interface InheritanceTest3 extends T4TS.OverridenName {
74 | SomeString3: string;
75 | Recursive3: Fooz.IFoobar;
76 | }
77 | /** Generated from T4TS.Example.Models.InheritanceTest4 **/
78 | export interface InheritanceTest4 {
79 | SomeString4: string;
80 | Recursive4: Fooz.IFoobar;
81 | }
82 | /** Generated from T4TS.Example.Models.InheritanceTestExternal **/
83 | export interface InheritanceTestExternal extends External.ModelFromDifferentProject {
84 | }
85 | /** Generated from T4TS.Example.Models.Inherited **/
86 | export interface OverridenName {
87 | OtherName?: string;
88 | Integers: number[];
89 | Doubles: number[];
90 | TwoDimList: number[][];
91 | [index: number]: Barfoo;
92 | }
93 | /** Generated from T4TS.Example.Models.PartialModelByEF **/
94 | export interface PartialModelByEF {
95 | SomeId: number;
96 | }
97 | /** Generated from T4TS.Example.Models.PartialModelByEF **/
98 | export interface PartialModelByEF {
99 | }
100 | /** Generated from T4TS.Example.Models.InheritsPartialModelByEF **/
101 | export interface InheritsPartialModelByEF extends T4TS.PartialModelByEF {
102 | NewProperty: string;
103 | }
104 | /** Generated from T4TS.Example.Models.Partial **/
105 | export interface Partial {
106 | FromFirstClass: string;
107 | }
108 | /** Generated from T4TS.Example.Models.Partial **/
109 | export interface Partial {
110 | FromSecondClass: string;
111 | AlsoSecondClass: boolean;
112 | }
113 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
114 | export interface BasicModel {
115 | MyProperty: number;
116 | SomeDateTime: string;
117 | }
118 | /** Generated from T4TS.Tests.Fixtures.Dictionary.DictionaryModel **/
119 | export interface DictionaryModel {
120 | IntKey: { [name: number]: T4TS.BasicModel};
121 | StringKey: { [name: string]: T4TS.BasicModel};
122 | [index: number]: T4TS.BasicModel;
123 | }
124 | /** Generated from T4TS.Tests.Fixtures.Enumerable.EnumerableModel **/
125 | export interface EnumerableModel {
126 | NormalProperty: number;
127 | PrimitiveArray: number[];
128 | PrimitiveList: number[];
129 | InterfaceArray: T4TS.BasicModel[];
130 | InterfaceList: T4TS.BasicModel[];
131 | DeepArray: number[][];
132 | DeepList: number[][];
133 | Generic: string[];
134 | }
135 | /** Generated from T4TS.Tests.Fixtures.ExtendsExplicit.ExtendsExplicitModel **/
136 | export interface ExtendsExplicitModel extends SomeFooBar {
137 | Basic: T4TS.BasicModel;
138 | }
139 | /** Generated from T4TS.Tests.Fixtures.ExternalProp.ExternalPropModel **/
140 | export interface ExternalPropModel {
141 | Basic: T4TS.BasicModel;
142 | External: External.ModelFromDifferentProject;
143 | }
144 | /** Generated from T4TS.Tests.Fixtures.Indexed.IndexedComplexModel **/
145 | export interface IndexedComplexModel {
146 | SomeProp: number;
147 | [index: number]: T4TS.BasicModel;
148 | }
149 | /** Generated from T4TS.Tests.Fixtures.Indexed.IndexedPrimitiveModel **/
150 | export interface IndexedPrimitiveModel {
151 | SomeProp: number;
152 | [index: number]: string;
153 | }
154 | /** Generated from T4TS.Tests.Fixtures.Inheritance.InheritanceModel **/
155 | export interface InheritanceModel extends T4TS.OtherInheritanceModel {
156 | OnInheritanceModel: T4TS.BasicModel;
157 | }
158 | /** Generated from T4TS.Tests.Fixtures.Inheritance.OtherInheritanceModel **/
159 | export interface OtherInheritanceModel extends External.ModelFromDifferentProject {
160 | OnOtherInheritanceModel: T4TS.BasicModel;
161 | }
162 | /** Generated from T4TS.Tests.Fixtures.Nullable.NullableModel **/
163 | export interface NullableModel {
164 | NullableInt: number;
165 | NullableDouble: number;
166 | }
167 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultCamelCaseMemberNamesModel **/
168 | export interface DefaultCamelCaseMemberNamesModel {
169 | SomeProp: string;
170 | }
171 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultCamelCaseMemberNamesOverrideModel **/
172 | export interface DefaultCamelCaseMemberNamesOverrideModel {
173 | SomeProp: string;
174 | }
175 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultInterfaceNamePrefixModel **/
176 | export interface DefaultInterfaceNamePrefixModel {
177 | SomeProp: string;
178 | }
179 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultInterfaceNamePrefixOverrideModel **/
180 | export interface PrefixOverrideDefaultInterfaceNamePrefixOverrideModel {
181 | OverrideName: string;
182 | }
183 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultModuleModel **/
184 | export interface DefaultModuleModel {
185 | SomeProp: string;
186 | }
187 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultOptionalModel **/
188 | export interface DefaultOptionalModel {
189 | SomeProp: string;
190 | }
191 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultOptionalOverrideModel **/
192 | export interface DefaultOptionalOverrideModel {
193 | SomeProp: string;
194 | }
195 | /** Generated from T4TS.Tests.Fixtures.Options.Default.UseNativeDatesModel **/
196 | export interface UseNativeDatesModel {
197 | SomeDateTime: string;
198 | SomeDateTimeOffset: string;
199 | }
200 | /** Generated from T4TS.Tests.Fixtures.Options.Override.InterfaceNamePrefixModel **/
201 | export interface FooInterfaceNamePrefixModel {
202 | SomeProp: string;
203 | }
204 | /** Generated from T4TS.Tests.Fixtures.Options.Override.InterfaceNameOverrideModel **/
205 | export interface Bar {
206 | SomeOtherProp: string;
207 | }
208 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberNameOverrideModel **/
209 | export interface MemberNameOverrideModel {
210 | OverriddenName: string;
211 | }
212 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberOptionalModel **/
213 | export interface MemberOptionalModel {
214 | Member?: string;
215 | }
216 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberCamelCaseModel **/
217 | export interface MemberCamelCaseModel {
218 | memberName: string;
219 | }
220 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberTypeModel **/
221 | export interface MemberTypeModel {
222 | NotANumber: number;
223 | }
224 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberIgnoreModel **/
225 | export interface MemberIgnoreModel {
226 | NotIgnored: string;
227 | }
228 | /** Generated from T4TS.Tests.Fixtures.Partial.PartialModel **/
229 | export interface PartialModel extends External.ModelFromDifferentProject {
230 | OnPartialModel: T4TS.BasicModel;
231 | }
232 | /** Generated from T4TS.Tests.Fixtures.Partial.PartialModel **/
233 | export interface PartialModel extends External.ModelFromDifferentProject {
234 | OnOtherPartialModel: T4TS.BasicModel;
235 | }
236 | /** Generated from T4TS.Tests.Traversal.Models.LocalModel **/
237 | export interface LocalModel {
238 | Id: number;
239 | Optional?: string;
240 | }
241 | /** Generated from T4TS.Tests.Traversal.Models.ReservedPropModel **/
242 | export interface ReservedPropModel {
243 | class: string;
244 | readonly: string;
245 | public?: boolean;
246 | }
247 | }
248 |
--------------------------------------------------------------------------------
/T4TS.Example/T4TS.tt:
--------------------------------------------------------------------------------
1 | <#@ template language="C#" debug="true" hostspecific="true" #>
2 | <#@ output extension=".d.ts" #>
3 | <#@ assembly name="System.Core" #>
4 | <#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
5 | <#@ assembly name="EnvDTE" #>
6 | <#@ assembly name="EnvDTE80" #>
7 | <#@ assembly name="$(SolutionDir)\\T4TS\\bin\\Debug\\T4TS.Dll" #>
8 | <#@ import namespace="System.Collections.Generic" #>
9 | <#@ import namespace="System.Linq" #>
10 | <#@ import namespace="System.Text" #>
11 | <#@ import namespace="EnvDTE" #>
12 | <#@ import namespace="T4TS" #>
13 | <#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
14 | <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
15 | <#@ Include File="T4TS.tt.settings.t4" #><#=
16 | T4TS.OutputFormatter.GetOutput(GetDataToRender(), GetSettings()) #><#+
17 |
18 | Settings settings = null;
19 | Settings GetSettings()
20 | {
21 | if (settings== null)
22 | settings = Settings.Parse(SettingsValues);
23 |
24 | return settings;
25 | }
26 |
27 | List GetDataToRender() {
28 | DTE dte = null;
29 |
30 | // Get the DTE service from the host
31 | var serviceProvider = Host as IServiceProvider;
32 | if (serviceProvider != null)
33 | dte = serviceProvider.GetService(typeof(SDTE)) as DTE;
34 |
35 | // Fail if we couldn't get the DTE. This can happen when trying to run in TextTransform.exe
36 | if (dte == null)
37 | throw new Exception("Can only execute through the Visual Studio host");
38 |
39 | var project = GetProjectContainingT4File(dte);
40 |
41 | if (project == null)
42 | throw new Exception("Could not find the VS project containing the T4TS file.");
43 |
44 | var generator = new CodeTraverser(dte.Solution, GetSettings());
45 | return generator.GetAllInterfaces().ToList();
46 | }
47 |
48 | Project GetProjectContainingT4File(DTE dte) {
49 |
50 | // Find the .tt file's ProjectItem
51 | ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
52 |
53 | // If the .tt file is not opened, open it
54 | if (projectItem.Document == null)
55 | projectItem.Open(Constants.vsViewKindCode);
56 |
57 | return projectItem.ContainingProject;
58 | }
59 | #>
--------------------------------------------------------------------------------
/T4TS.Example/T4TS.tt.settings.t4:
--------------------------------------------------------------------------------
1 | <#+
2 | ///
3 | /// These settings can be used to customize the output of T4TS.
4 | /// The default for all settings are determined by T4TS.tt in ReadSettings().
5 | ///
6 | readonly Dictionary SettingsValues = new Dictionary()
7 | {
8 | // The default module of the generated interface. If a module is
9 | // not specified by the TypeScriptInterfaceAttribute, the interface
10 | // will belong to this module (may be empty, in which case the
11 | // interface will be globally accessible).
12 | // Type: string, defaults to "T4TS" if not specified.
13 | { "DefaultModule", null },
14 |
15 | // The default value for the Optional flag for an interface member.
16 | // If not specified by the TypeScriptInterfaceAttribute, the Optional
17 | // flag will be set to this value. If the Optional flag is true, the
18 | // generated member will look like "member?: type" instead of "member: type".
19 | // Type: bool?, defaults to false if not specified.
20 | { "DefaultOptional", null },
21 |
22 | // The default value for the CamelCase flag for an interface member name.
23 | // If set to true, the first character of member names will be lower cased.
24 | // Type: bool?, defaults to false if not specified.
25 | { "DefaultCamelCaseMemberNames", null },
26 |
27 | // The default string to prefix interface names with. For instance, you
28 | // might want to prefix the names with an "I" to get conventional
29 | // interface names.
30 | // Type: string, defaults to "" if not specified.
31 | { "DefaultInterfaceNamePrefix", null },
32 |
33 | // The version of Typescript that is targeted. This is required to handle
34 | // breaking changes in the language grammar and/or compiler.
35 | // Type: System.Version
36 | { "CompatibilityVersion", null },
37 |
38 | // The default value for DateTime type translation.
39 | // Type: bool?, defaults to false if not specified.
40 | { "UseNativeDates", null }
41 | };
42 | #>
--------------------------------------------------------------------------------
/T4TS.Tests/CodeTraverserTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System.Linq;
3 | using T4TS.Example.Models;
4 | using T4TS.Tests.Traversal.Models;
5 | using T4TS.Tests.Utils;
6 |
7 | namespace T4TS.Tests.Traversal
8 | {
9 | [TestClass]
10 | public class CodeTraverserTests
11 | {
12 | [TestMethod]
13 | public void ShouldBuildInterfacesFromMarkedClassesOnly()
14 | {
15 | var solution = DTETransformer.BuildDteSolution(
16 | typeof(LocalModel), // has the TypeScriptInterface attribute
17 | typeof(ModelFromDifferentProject), // has the TypeScriptInterface attribute
18 | typeof(string) // has no TypeScriptInterface attribute
19 | );
20 |
21 | var codeTraverser = new CodeTraverser(solution, new Settings());
22 | Assert.AreEqual(2, codeTraverser.GetAllInterfaces().Count());
23 | }
24 |
25 | [TestMethod]
26 | public void ShouldWorkIfSolutionContainsPartialClasses() {
27 | //this may not make much sense, but this is my best guess at mimicking partial classes...
28 | //Actually traceing out all the TypeScriptInterfaces in the T4TS.Example solution contains these:
29 | // ...
30 | //T4TS.Example.Models.PartialModelByEF
31 | //T4TS.Example.Models.PartialModelByEF
32 | //T4TS.Example.Models.InheritsPartialModelByEF
33 | //T4TS.Example.Models.Partial
34 | //T4TS.Example.Models.Partial
35 | // ...
36 |
37 | var solution = DTETransformer.BuildDteSolution(
38 | typeof(T4TS.Tests.Fixtures.Partial.PartialModel),
39 | typeof(T4TS.Tests.Fixtures.Partial.PartialModel),
40 | typeof(T4TS.Tests.Fixtures.Partial.InheritsFromPartialModel)
41 | );
42 |
43 | var codeTraverser = new CodeTraverser(solution, new Settings());
44 | var allModules = codeTraverser.GetAllInterfaces();
45 | Assert.AreEqual(1, allModules.Count());
46 | Assert.AreEqual(3, allModules.First().Interfaces.Count());
47 | }
48 |
49 | [TestMethod]
50 | public void ShouldHandleReservedPropNames()
51 | {
52 | var solution = DTETransformer.BuildDteSolution(typeof(ReservedPropModel));
53 | var codeTraverser = new CodeTraverser(solution, new Settings());
54 |
55 | var modules = codeTraverser.GetAllInterfaces();
56 | var interfaces = modules.Single().Interfaces;
57 | var modelInterface = interfaces.Single();
58 |
59 | var classProp = modelInterface.Members.SingleOrDefault(m => m.Name == "class");
60 | var readonlyProp = modelInterface.Members.SingleOrDefault(m => m.Name == "readonly");
61 | var publicProp = modelInterface.Members.SingleOrDefault(m => m.Name == "public");
62 |
63 | Assert.AreEqual(3, modelInterface.Members.Count);
64 |
65 | Assert.IsNotNull(classProp);
66 | Assert.IsNotNull(readonlyProp);
67 | Assert.IsNotNull(publicProp);
68 |
69 | Assert.IsTrue(publicProp.Optional);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Basic/BasicModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Basic
8 | {
9 | [TypeScriptInterface]
10 | public class BasicModel
11 | {
12 | public int MyProperty { get; set; }
13 | public DateTime SomeDateTime { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Basic/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Basic
5 | {
6 | [TestClass]
7 | public class Test
8 | {
9 | [TestMethod]
10 | public void BasicModelHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(BasicModel)
15 | ).ToEqual(ExpectedOutput);
16 | }
17 |
18 | const string ExpectedOutput = @"
19 | /****************************************************************************
20 | Generated by T4TS.tt - don't make any changes in this file
21 | ****************************************************************************/
22 |
23 | declare module T4TS {
24 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
25 | export interface BasicModel {
26 | MyProperty: number;
27 | SomeDateTime: string;
28 | }
29 | }
30 | ";
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Dictionary/DictionaryModel.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using T4TS.Tests.Fixtures.Basic;
3 |
4 | namespace T4TS.Tests.Fixtures.Dictionary
5 | {
6 | [TypeScriptInterface]
7 | public class DictionaryModel : List
8 | {
9 | public Dictionary IntKey { get; set; }
10 | public IDictionary StringKey { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Dictionary/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Fixtures.Basic;
3 | using T4TS.Tests.Utils;
4 |
5 | namespace T4TS.Tests.Fixtures.Dictionary
6 | {
7 | [TestClass]
8 | public class Test
9 | {
10 | [TestMethod]
11 | public void DictionaryModelHasExpectedOutput()
12 | {
13 | // Expect
14 | new OutputFor(
15 | typeof(BasicModel),
16 | typeof(DictionaryModel)
17 | ).ToEqual(ExpectedOutput);
18 | }
19 |
20 | const string ExpectedOutput = @"
21 | /****************************************************************************
22 | Generated by T4TS.tt - don't make any changes in this file
23 | ****************************************************************************/
24 |
25 | declare module T4TS {
26 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
27 | export interface BasicModel {
28 | MyProperty: number;
29 | SomeDateTime: string;
30 | }
31 | /** Generated from T4TS.Tests.Fixtures.Dictionary.DictionaryModel **/
32 | export interface DictionaryModel {
33 | IntKey: { [name: number]: T4TS.BasicModel};
34 | StringKey: { [name: string]: T4TS.BasicModel};
35 | [index: number]: T4TS.BasicModel;
36 | }
37 | }
38 | ";
39 | }
40 | }
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Enumerable/EnumerableModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using T4TS.Example.Models;
7 | using T4TS.Tests.Fixtures.Basic;
8 |
9 | namespace T4TS.Tests.Fixtures.Enumerable
10 | {
11 | [TypeScriptInterface]
12 | public partial class EnumerableModel
13 | {
14 | public int NormalProperty { get; set; }
15 | public int[] PrimitiveArray { get; set; }
16 | public List PrimitiveList { get; set; }
17 | public BasicModel[] InterfaceArray { get; set; }
18 | public List InterfaceList { get; set; }
19 | public int[][] DeepArray { get; set; }
20 | public List> DeepList { get; set; }
21 | public IEnumerable Generic { get; set; }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Enumerable/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Example.Models;
3 | using T4TS.Tests.Fixtures.Basic;
4 | using T4TS.Tests.Utils;
5 |
6 | namespace T4TS.Tests.Fixtures.Enumerable
7 | {
8 | [TestClass]
9 | public class Test
10 | {
11 | [TestMethod]
12 | public void EnumerableModelHasExpectedOutput()
13 | {
14 | // Expect
15 | new OutputFor(
16 | typeof(EnumerableModel),
17 | typeof(BasicModel)
18 | ).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module T4TS {
27 | /** Generated from T4TS.Tests.Fixtures.Enumerable.EnumerableModel **/
28 | export interface EnumerableModel {
29 | NormalProperty: number;
30 | PrimitiveArray: number[];
31 | PrimitiveList: number[];
32 | InterfaceArray: T4TS.BasicModel[];
33 | InterfaceList: T4TS.BasicModel[];
34 | DeepArray: number[][];
35 | DeepList: number[][];
36 | Generic: string[];
37 | }
38 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
39 | export interface BasicModel {
40 | MyProperty: number;
41 | SomeDateTime: string;
42 | }
43 | }
44 | ";
45 |
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/ExtendsExplicit/ExtendsExplicit.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using T4TS.Example.Models;
7 | using T4TS.Tests.Fixtures.Basic;
8 |
9 | namespace T4TS.Tests.Fixtures.ExtendsExplicit
10 | {
11 | [TypeScriptInterface(Extends="SomeFooBar")]
12 | public class ExtendsExplicitModel
13 | {
14 | public BasicModel Basic { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/ExtendsExplicit/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Example.Models;
3 | using T4TS.Tests.Fixtures.Basic;
4 | using T4TS.Tests.Utils;
5 |
6 | namespace T4TS.Tests.Fixtures.ExtendsExplicit
7 | {
8 | [TestClass]
9 | public class Test
10 | {
11 | [TestMethod]
12 | public void ExtendsExplicitModelHasExpectedOutput()
13 | {
14 | // Expect
15 | new OutputFor(
16 | typeof(ExtendsExplicitModel),
17 | typeof(BasicModel)
18 | ).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module T4TS {
27 | /** Generated from T4TS.Tests.Fixtures.ExtendsExplicit.ExtendsExplicitModel **/
28 | export interface ExtendsExplicitModel extends SomeFooBar {
29 | Basic: T4TS.BasicModel;
30 | }
31 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
32 | export interface BasicModel {
33 | MyProperty: number;
34 | SomeDateTime: string;
35 | }
36 | }
37 | ";
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/ExternalProp/ExternalPropModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using T4TS.Example.Models;
7 | using T4TS.Tests.Fixtures.Basic;
8 |
9 | namespace T4TS.Tests.Fixtures.ExternalProp
10 | {
11 | [TypeScriptInterface]
12 | public class ExternalPropModel
13 | {
14 | public BasicModel Basic { get; set; }
15 | public ModelFromDifferentProject External { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/ExternalProp/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Example.Models;
3 | using T4TS.Tests.Fixtures.Basic;
4 | using T4TS.Tests.Utils;
5 |
6 | namespace T4TS.Tests.Fixtures.ExternalProp
7 | {
8 | [TestClass]
9 | public class Test
10 | {
11 | [TestMethod]
12 | public void ExternalPropModelHasExpectedOutput()
13 | {
14 | // Expect
15 | new OutputFor(
16 | typeof(ExternalPropModel),
17 | typeof(ModelFromDifferentProject),
18 | typeof(BasicModel)
19 | ).ToEqual(ExpectedOutput);
20 | }
21 |
22 | const string ExpectedOutput = @"
23 | /****************************************************************************
24 | Generated by T4TS.tt - don't make any changes in this file
25 | ****************************************************************************/
26 |
27 | declare module External {
28 | /** Generated from T4TS.Example.Models.ModelFromDifferentProject **/
29 | export interface ModelFromDifferentProject {
30 | Id: number;
31 | }
32 | }
33 |
34 | declare module T4TS {
35 | /** Generated from T4TS.Tests.Fixtures.ExternalProp.ExternalPropModel **/
36 | export interface ExternalPropModel {
37 | Basic: T4TS.BasicModel;
38 | External: External.ModelFromDifferentProject;
39 | }
40 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
41 | export interface BasicModel {
42 | MyProperty: number;
43 | SomeDateTime: string;
44 | }
45 | }
46 | ";
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Indexed/IndexedModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using T4TS.Tests.Fixtures.Basic;
7 |
8 | namespace T4TS.Tests.Fixtures.Indexed
9 | {
10 | [TypeScriptInterface]
11 | public class IndexedComplexModel : List
12 | {
13 | public int SomeProp { get; set; }
14 | }
15 |
16 | [TypeScriptInterface]
17 | public class IndexedPrimitiveModel : List
18 | {
19 | public int SomeProp { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Indexed/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Fixtures.Basic;
3 | using T4TS.Tests.Utils;
4 |
5 | namespace T4TS.Tests.Fixtures.Indexed
6 | {
7 | [TestClass]
8 | public class Test
9 | {
10 | [TestMethod]
11 | public void IndexedModelHasExpectedOutput()
12 | {
13 | // Expect
14 | new OutputFor(
15 | typeof(BasicModel),
16 | typeof(IndexedComplexModel),
17 | typeof(IndexedPrimitiveModel)
18 | ).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module T4TS {
27 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
28 | export interface BasicModel {
29 | MyProperty: number;
30 | SomeDateTime: string;
31 | }
32 | /** Generated from T4TS.Tests.Fixtures.Indexed.IndexedComplexModel **/
33 | export interface IndexedComplexModel {
34 | SomeProp: number;
35 | [index: number]: T4TS.BasicModel;
36 | }
37 | /** Generated from T4TS.Tests.Fixtures.Indexed.IndexedPrimitiveModel **/
38 | export interface IndexedPrimitiveModel {
39 | SomeProp: number;
40 | [index: number]: string;
41 | }
42 | }
43 | ";
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Inheritance/InheritanceModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using T4TS.Example.Models;
7 | using T4TS.Tests.Fixtures.Basic;
8 |
9 | namespace T4TS.Tests.Fixtures.Inheritance
10 | {
11 | [TypeScriptInterface]
12 | public class InheritanceModel : OtherInheritanceModel
13 | {
14 | public BasicModel OnInheritanceModel { get; set; }
15 | }
16 |
17 | [TypeScriptInterface]
18 | public class OtherInheritanceModel : ModelFromDifferentProject
19 | {
20 | public BasicModel OnOtherInheritanceModel { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Inheritance/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Example.Models;
3 | using T4TS.Tests.Fixtures.Basic;
4 | using T4TS.Tests.Utils;
5 |
6 | namespace T4TS.Tests.Fixtures.Inheritance
7 | {
8 | [TestClass]
9 | public class Test
10 | {
11 | [TestMethod]
12 | public void InheritanceModelHasExpectedOutput()
13 | {
14 | // Expect
15 | new OutputFor(
16 | typeof(InheritanceModel),
17 | typeof(OtherInheritanceModel),
18 | typeof(ModelFromDifferentProject),
19 | typeof(BasicModel)
20 | ).ToEqual(ExpectedOutput);
21 | }
22 |
23 | const string ExpectedOutput = @"
24 | /****************************************************************************
25 | Generated by T4TS.tt - don't make any changes in this file
26 | ****************************************************************************/
27 |
28 | declare module External {
29 | /** Generated from T4TS.Example.Models.ModelFromDifferentProject **/
30 | export interface ModelFromDifferentProject {
31 | Id: number;
32 | }
33 | }
34 |
35 | declare module T4TS {
36 | /** Generated from T4TS.Tests.Fixtures.Inheritance.InheritanceModel **/
37 | export interface InheritanceModel extends T4TS.OtherInheritanceModel {
38 | OnInheritanceModel: T4TS.BasicModel;
39 | }
40 | /** Generated from T4TS.Tests.Fixtures.Inheritance.OtherInheritanceModel **/
41 | export interface OtherInheritanceModel extends External.ModelFromDifferentProject {
42 | OnOtherInheritanceModel: T4TS.BasicModel;
43 | }
44 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
45 | export interface BasicModel {
46 | MyProperty: number;
47 | SomeDateTime: string;
48 | }
49 | }
50 | ";
51 |
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Nullable/NullableModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Nullable
8 | {
9 | [TypeScriptInterface]
10 | public class NullableModel
11 | {
12 | public int? NullableInt { get; set; }
13 | public double? NullableDouble { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Nullable/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Nullable
5 | {
6 | [TestClass]
7 | public class Test
8 | {
9 | [TestMethod]
10 | public void NullableModelHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(NullableModel)
15 | ).ToEqual(ExpectedOutput);
16 | }
17 |
18 | const string ExpectedOutput = @"
19 | /****************************************************************************
20 | Generated by T4TS.tt - don't make any changes in this file
21 | ****************************************************************************/
22 |
23 | declare module T4TS {
24 | /** Generated from T4TS.Tests.Fixtures.Nullable.NullableModel **/
25 | export interface NullableModel {
26 | NullableInt: number;
27 | NullableDouble: number;
28 | }
29 | }
30 | ";
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultCamelCaseMemberNamesModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Options.Default
8 | {
9 | [TypeScriptInterface]
10 | public class DefaultCamelCaseMemberNamesModel
11 | {
12 | public string SomeProp { get; set; }
13 | }
14 |
15 | [TypeScriptInterface]
16 | public class DefaultCamelCaseMemberNamesOverrideModel
17 | {
18 | [TypeScriptMember(CamelCase=false)]
19 | public string SomeProp { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultCamelCaseMemberNamesTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Options.Default
5 | {
6 | [TestClass]
7 | public class DefaultCamelCaseMemberNamesTest
8 | {
9 | [TestMethod]
10 | public void DefaultCamelCaseMemberNamesHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(DefaultCamelCaseMemberNamesModel),
15 | typeof(DefaultCamelCaseMemberNamesOverrideModel)
16 | ).With(new Settings {
17 | DefaultCamelCaseMemberNames = true
18 | }).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module T4TS {
27 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultCamelCaseMemberNamesModel **/
28 | export interface DefaultCamelCaseMemberNamesModel {
29 | someProp: string;
30 | }
31 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultCamelCaseMemberNamesOverrideModel **/
32 | export interface DefaultCamelCaseMemberNamesOverrideModel {
33 | SomeProp: string;
34 | }
35 | }
36 | ";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultInterfaceNamePrefixModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Options.Default
8 | {
9 | [TypeScriptInterface]
10 | public class DefaultInterfaceNamePrefixModel
11 | {
12 | public string SomeProp { get; set; }
13 | }
14 |
15 | [TypeScriptInterface(NamePrefix="PrefixOverride")]
16 | public class DefaultInterfaceNamePrefixOverrideModel
17 | {
18 | [TypeScriptMember(Name="OverrideName")]
19 | public string SomeProp { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultInterfaceNamePrefixTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Options.Default
5 | {
6 | [TestClass]
7 | public class DefaultInterfaceNamePrefixTest
8 | {
9 | [TestMethod]
10 | public void DefaultCamelCaseMemberNamesHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(DefaultInterfaceNamePrefixModel),
15 | typeof(DefaultInterfaceNamePrefixOverrideModel)
16 | ).With(new Settings {
17 | DefaultInterfaceNamePrefix = "InterfacePrefixTest"
18 | }).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module T4TS {
27 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultInterfaceNamePrefixModel **/
28 | export interface InterfacePrefixTestDefaultInterfaceNamePrefixModel {
29 | SomeProp: string;
30 | }
31 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultInterfaceNamePrefixOverrideModel **/
32 | export interface PrefixOverrideDefaultInterfaceNamePrefixOverrideModel {
33 | OverrideName: string;
34 | }
35 | }
36 | ";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultModuleModels.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Options.Default
8 | {
9 | [TypeScriptInterface]
10 | public class DefaultModuleModel
11 | {
12 | public string SomeProp { get; set; }
13 | }
14 |
15 | [TypeScriptInterface(Module="Override")]
16 | public class DefaultModuleOverrideModel
17 | {
18 | public string SomeProp { get; set; }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultModuleTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Options.Default
5 | {
6 | [TestClass]
7 | public class DefaultModuleTest
8 | {
9 | [TestMethod]
10 | public void DefaultModuleSettingHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(DefaultModuleModel),
15 | typeof(DefaultModuleOverrideModel)
16 | ).With(new Settings {
17 | DefaultModule = "Foobar"
18 | }).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module Foobar {
27 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultModuleModel **/
28 | export interface DefaultModuleModel {
29 | SomeProp: string;
30 | }
31 | }
32 |
33 | declare module Override {
34 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultModuleOverrideModel **/
35 | export interface DefaultModuleOverrideModel {
36 | SomeProp: string;
37 | }
38 | }
39 | ";
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultOptionalModels.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Options.Default
8 | {
9 | [TypeScriptInterface]
10 | public class DefaultOptionalModel
11 | {
12 | public string SomeProp { get; set; }
13 | }
14 |
15 | [TypeScriptInterface]
16 | public class DefaultOptionalOverrideModel
17 | {
18 | [TypeScriptMember(Optional = false)]
19 | public string SomeProp { get; set; }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/DefaultOptionalTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Options.Default
5 | {
6 | [TestClass]
7 | public class DefaultOptionalTest
8 | {
9 | [TestMethod]
10 | public void DefaultOptionalSettingHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(DefaultOptionalModel),
15 | typeof(DefaultOptionalOverrideModel)
16 | ).With(new Settings {
17 | DefaultOptional = true
18 | }).ToEqual(ExpectedOutput);
19 | }
20 |
21 | const string ExpectedOutput = @"
22 | /****************************************************************************
23 | Generated by T4TS.tt - don't make any changes in this file
24 | ****************************************************************************/
25 |
26 | declare module T4TS {
27 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultOptionalModel **/
28 | export interface DefaultOptionalModel {
29 | SomeProp?: string;
30 | }
31 | /** Generated from T4TS.Tests.Fixtures.Options.Default.DefaultOptionalOverrideModel **/
32 | export interface DefaultOptionalOverrideModel {
33 | SomeProp: string;
34 | }
35 | }
36 | ";
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/UseNativeDatesModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Options.Default
8 | {
9 | [TypeScriptInterface]
10 | public class UseNativeDatesModel
11 | {
12 | public DateTime SomeDateTime { get; set; }
13 | public DateTimeOffset SomeDateTimeOffset { get; set; }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Default/UseNativeDatesTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Options.Default
5 | {
6 | [TestClass]
7 | public class UseNativeDatesTest
8 | {
9 | [TestMethod]
10 | public void UseNativeDatesSettingHasExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(UseNativeDatesModel)
15 | ).With(new Settings {
16 | UseNativeDates = true
17 | }).ToEqual(ExpectedOutput);
18 | }
19 |
20 | const string ExpectedOutput = @"
21 | /****************************************************************************
22 | Generated by T4TS.tt - don't make any changes in this file
23 | ****************************************************************************/
24 |
25 | declare module T4TS {
26 | /** Generated from T4TS.Tests.Fixtures.Options.Default.UseNativeDatesModel **/
27 | export interface UseNativeDatesModel {
28 | SomeDateTime: Date;
29 | SomeDateTimeOffset: Date;
30 | }
31 | }
32 | ";
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Override/OverrideModels.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Fixtures.Options.Override
8 | {
9 | [TypeScriptInterface(NamePrefix = "Foo")]
10 | public class InterfaceNamePrefixModel
11 | {
12 | public string SomeProp { get; set; }
13 | }
14 |
15 | [TypeScriptInterface(Name = "Bar")]
16 | public class InterfaceNameOverrideModel
17 | {
18 | public string SomeOtherProp { get; set; }
19 | }
20 |
21 | [TypeScriptInterface(Module = "SomeModule")]
22 | public class ModuleNameOverrideModel
23 | {
24 | public string SomeThirdProp { get; set; }
25 | }
26 |
27 | [TypeScriptInterface]
28 | public class MemberNameOverrideModel
29 | {
30 | [TypeScriptMember(Name = "OverriddenName")]
31 | public string OriginalName { get; set; }
32 | }
33 |
34 | [TypeScriptInterface]
35 | public class MemberOptionalModel
36 | {
37 | [TypeScriptMember(Optional = true)]
38 | public string Member { get; set; }
39 | }
40 |
41 | [TypeScriptInterface]
42 | public class MemberCamelCaseModel
43 | {
44 | [TypeScriptMember(CamelCase = true)]
45 | public string MemberName { get; set; }
46 | }
47 |
48 | [TypeScriptInterface]
49 | public class MemberTypeModel
50 | {
51 | [TypeScriptMember(Type = "number")]
52 | public string NotANumber { get; set; }
53 | }
54 |
55 | [TypeScriptInterface]
56 | public class MemberIgnoreModel
57 | {
58 | [TypeScriptMember(Ignore = true)]
59 | public string Ignored { get; set; }
60 |
61 | [TypeScriptMember(Ignore = false)]
62 | public string NotIgnored { get; set; }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Options/Override/OverrideTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Tests.Utils;
3 |
4 | namespace T4TS.Tests.Fixtures.Options.Override
5 | {
6 | [TestClass]
7 | public class OverrideTests
8 | {
9 | [TestMethod]
10 | public void OverrideModelsHaveExpectedOutput()
11 | {
12 | // Expect
13 | new OutputFor(
14 | typeof(InterfaceNamePrefixModel),
15 | typeof(InterfaceNameOverrideModel),
16 | typeof(ModuleNameOverrideModel),
17 | typeof(MemberNameOverrideModel),
18 | typeof(MemberOptionalModel),
19 | typeof(MemberCamelCaseModel),
20 | typeof(MemberTypeModel),
21 | typeof(MemberIgnoreModel)
22 | ).ToEqual(ExpectedOutput);
23 | }
24 |
25 | const string ExpectedOutput = @"
26 | /****************************************************************************
27 | Generated by T4TS.tt - don't make any changes in this file
28 | ****************************************************************************/
29 |
30 | declare module SomeModule {
31 | /** Generated from T4TS.Tests.Fixtures.Options.Override.ModuleNameOverrideModel **/
32 | export interface ModuleNameOverrideModel {
33 | SomeThirdProp: string;
34 | }
35 | }
36 |
37 | declare module T4TS {
38 | /** Generated from T4TS.Tests.Fixtures.Options.Override.InterfaceNamePrefixModel **/
39 | export interface FooInterfaceNamePrefixModel {
40 | SomeProp: string;
41 | }
42 | /** Generated from T4TS.Tests.Fixtures.Options.Override.InterfaceNameOverrideModel **/
43 | export interface Bar {
44 | SomeOtherProp: string;
45 | }
46 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberNameOverrideModel **/
47 | export interface MemberNameOverrideModel {
48 | OverriddenName: string;
49 | }
50 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberOptionalModel **/
51 | export interface MemberOptionalModel {
52 | Member?: string;
53 | }
54 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberCamelCaseModel **/
55 | export interface MemberCamelCaseModel {
56 | memberName: string;
57 | }
58 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberTypeModel **/
59 | export interface MemberTypeModel {
60 | NotANumber: number;
61 | }
62 | /** Generated from T4TS.Tests.Fixtures.Options.Override.MemberIgnoreModel **/
63 | export interface MemberIgnoreModel {
64 | NotIgnored: string;
65 | }
66 | }
67 | ";
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Partial/PartialModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using T4TS.Example.Models;
7 | using T4TS.Tests.Fixtures.Basic;
8 |
9 | namespace T4TS.Tests.Fixtures.Partial
10 | {
11 | [TypeScriptInterface]
12 | public partial class PartialModel
13 | {
14 | public BasicModel OnPartialModel { get; set; }
15 | }
16 |
17 | public partial class PartialModel : ModelFromDifferentProject
18 | {
19 | public BasicModel OnOtherPartialModel { get; set; }
20 | }
21 |
22 | [TypeScriptInterface]
23 | public partial class InheritsFromPartialModel : PartialModel
24 | {
25 | public string NewProperty { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/T4TS.Tests/Fixtures/Partial/Test.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using T4TS.Example.Models;
3 | using T4TS.Tests.Fixtures.Basic;
4 | using T4TS.Tests.Utils;
5 |
6 | namespace T4TS.Tests.Fixtures.Partial
7 | {
8 | [TestClass]
9 | public class Test
10 | {
11 | [TestMethod]
12 | public void PartialModelHasExpectedOutput()
13 | {
14 | // Expect
15 | new OutputFor(
16 | typeof(PartialModel),
17 | typeof(ModelFromDifferentProject),
18 | typeof(BasicModel)
19 | ).ToEqual(ExpectedOutput);
20 | }
21 |
22 | const string ExpectedOutput = @"
23 | /****************************************************************************
24 | Generated by T4TS.tt - don't make any changes in this file
25 | ****************************************************************************/
26 |
27 | declare module External {
28 | /** Generated from T4TS.Example.Models.ModelFromDifferentProject **/
29 | export interface ModelFromDifferentProject {
30 | Id: number;
31 | }
32 | }
33 |
34 | declare module T4TS {
35 | /** Generated from T4TS.Tests.Fixtures.Partial.PartialModel **/
36 | export interface PartialModel extends External.ModelFromDifferentProject {
37 | OnPartialModel: T4TS.BasicModel;
38 | OnOtherPartialModel: T4TS.BasicModel;
39 | }
40 | /** Generated from T4TS.Tests.Fixtures.Basic.BasicModel **/
41 | export interface BasicModel {
42 | MyProperty: number;
43 | SomeDateTime: string;
44 | }
45 | }
46 | ";
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/T4TS.Tests/Models/LocalModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Models
8 | {
9 | [TypeScriptInterface]
10 | public class LocalModel
11 | {
12 | public int Id { get; set; }
13 |
14 | [TypeScriptMember(Optional = true)]
15 | public string Optional { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/T4TS.Tests/Models/ReservedPropModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Models
8 | {
9 | [TypeScriptInterface]
10 | public class ReservedPropModel
11 | {
12 | public string @class { get; set; }
13 |
14 | public string @readonly { get; set; }
15 |
16 | [TypeScriptMember(Optional = true)]
17 | public bool @public { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/T4TS.Tests/Output/MemberOutputAppenderTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace T4TS.Tests
9 | {
10 | [TestClass]
11 | public class MemberOutputAppenderTests
12 | {
13 | [TestMethod]
14 | public void TypescriptVersion083YieldsBool()
15 | {
16 | var sb = new StringBuilder();
17 | var member = new TypeScriptInterfaceMember
18 | {
19 | Name = "Foo",
20 | Type = new BoolType()
21 | };
22 |
23 | var appender = new MemberOutputAppender(sb, 0, new Settings
24 | {
25 | CompatibilityVersion = new Version(0, 8, 3)
26 | });
27 |
28 | appender.AppendOutput(member);
29 | Assert.AreEqual("Foo: bool;", sb.ToString().Trim());
30 | }
31 |
32 | [TestMethod]
33 | public void TypescriptVersion090YieldsBoolean()
34 | {
35 | var sb = new StringBuilder();
36 | var member = new TypeScriptInterfaceMember
37 | {
38 | Name = "Foo",
39 | Type = new BoolType()
40 | };
41 |
42 | var appender = new MemberOutputAppender(sb, 0, new Settings
43 | {
44 | CompatibilityVersion = new Version(0, 9, 0)
45 | });
46 |
47 | appender.AppendOutput(member);
48 | Assert.AreEqual("Foo: boolean;", sb.ToString().Trim());
49 | }
50 |
51 | [TestMethod]
52 | public void DefaultTypescriptVersionYieldsBoolean()
53 | {
54 | var sb = new StringBuilder();
55 | var member = new TypeScriptInterfaceMember
56 | {
57 | Name = "Foo",
58 | Type = new BoolType()
59 | };
60 |
61 | var appender = new MemberOutputAppender(sb, 0, new Settings
62 | {
63 | CompatibilityVersion = null
64 | });
65 |
66 | appender.AppendOutput(member);
67 | Assert.AreEqual("Foo: boolean;", sb.ToString().Trim());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/T4TS.Tests/Output/ModuleOutputAppenderTests.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace T4TS.Tests
9 | {
10 | [TestClass]
11 | public class ModuleOutputAppenderTests
12 | {
13 | [TestMethod]
14 | public void TypescriptVersion083YieldsModule()
15 | {
16 | var sb = new StringBuilder();
17 | var module = new TypeScriptModule
18 | {
19 | QualifiedName = "Foo"
20 | };
21 |
22 | var appender = new ModuleOutputAppender(sb, 0, new Settings
23 | {
24 | CompatibilityVersion = new Version(0, 8, 3)
25 | });
26 |
27 | appender.AppendOutput(module);
28 | Assert.IsTrue(sb.ToString().StartsWith("module "));
29 | }
30 |
31 | [TestMethod]
32 | public void TypescriptVersion090YieldsDeclareModule()
33 | {
34 | var sb = new StringBuilder();
35 | var module = new TypeScriptModule
36 | {
37 | QualifiedName = "Foo"
38 | };
39 |
40 | var appender = new ModuleOutputAppender(sb, 0, new Settings
41 | {
42 | CompatibilityVersion = new Version(0, 9, 0)
43 | });
44 |
45 | appender.AppendOutput(module);
46 | Assert.IsTrue(sb.ToString().StartsWith("declare module "));
47 | }
48 |
49 | [TestMethod]
50 | public void DefaultTypescriptVersionYieldsDeclareModule()
51 | {
52 | var sb = new StringBuilder();
53 | var module = new TypeScriptModule
54 | {
55 | QualifiedName = "Foo"
56 | };
57 |
58 | var appender = new ModuleOutputAppender(sb, 0, new Settings
59 | {
60 | CompatibilityVersion = null
61 | });
62 |
63 | appender.AppendOutput(module);
64 | Assert.IsTrue(sb.ToString().StartsWith("declare module "));
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/T4TS.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("5b6339b6-335f-4493-bdb2-623ecd1d7d83")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS.Tests/T4TS.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {93F7F024-CE32-476E-995A-0B6AA5A649F3}
7 | Library
8 | Properties
9 | T4TS.Tests
10 | T4TS.Tests
11 | v4.5
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 10.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 | ..\
21 | true
22 |
23 |
24 | true
25 | full
26 | false
27 | bin\Debug\
28 | DEBUG;TRACE
29 | prompt
30 | 4
31 | false
32 |
33 |
34 | pdbonly
35 | true
36 | bin\Release\
37 | TRACE
38 | prompt
39 | 4
40 | false
41 |
42 |
43 |
44 | False
45 |
46 |
47 | False
48 |
49 |
50 |
51 |
52 | ..\packages\Moq.4.2.1408.0717\lib\net40\Moq.dll
53 |
54 |
55 |
56 |
57 | 3.5
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | {af50a5e0-791d-47d4-91fe-56a7ce4577eb}
119 | T4TS.Attributes
120 |
121 |
122 | {93ee0391-db26-40cc-a613-6ca32e3eeb18}
123 | T4TS.Example.Models
124 |
125 |
126 | {2b9cfea6-586a-4e3b-8575-79447d5dc086}
127 | T4TS
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | False
139 |
140 |
141 | False
142 |
143 |
144 | False
145 |
146 |
147 | False
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 | This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
158 |
159 |
160 |
161 |
168 |
--------------------------------------------------------------------------------
/T4TS.Tests/Traversal/ClassTraversalTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using T4TS.Tests.Utils;
4 | using T4TS.Tests.Traversal.Models;
5 |
6 | namespace T4TS.Tests.Traversal
7 | {
8 | [TestClass]
9 | public class ClassTraversalTests
10 | {
11 | class M
12 | {
13 | public int A { get; set; }
14 | public int B { get; set; }
15 | public int C { get; set; }
16 | }
17 |
18 | [TestMethod]
19 | public void ShouldVisitEachProperty()
20 | {
21 | var codeClass = DTETransformer.BuildDteClass(typeof(M));
22 | int callCount = 0;
23 |
24 | var expectedNames = new string[] {"A","B","C"};
25 |
26 | new ClassTraverser(codeClass, (p) => { Assert.AreEqual(expectedNames[callCount++], p.Name); });
27 | Assert.AreEqual(3, callCount);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/T4TS.Tests/Traversal/Models/LocalModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Traversal.Models
8 | {
9 | [TypeScriptInterface]
10 | public class LocalModel
11 | {
12 | public int Id { get; set; }
13 |
14 | [TypeScriptMember(Optional = true)]
15 | public string Optional { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/T4TS.Tests/Traversal/Models/ReservedPropModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS.Tests.Traversal.Models
8 | {
9 | [TypeScriptInterface]
10 | public class ReservedPropModel
11 | {
12 | public string @class { get; set; }
13 |
14 | public string @readonly { get; set; }
15 |
16 | [TypeScriptMember(Optional = true)]
17 | public bool @public { get; set; }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/T4TS.Tests/Traversal/NamespaceTraverserTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using T4TS.Tests.Utils;
4 | using EnvDTE;
5 | using System.Collections;
6 |
7 | namespace T4TS.Tests.Traversal
8 | {
9 | [TestClass]
10 | public class NamespaceTraverserTests
11 | {
12 | class M
13 | {
14 | public int A { get; set; }
15 | }
16 |
17 | class N
18 | {
19 | public int A { get; set; }
20 | }
21 |
22 | [TestMethod]
23 | public void ShouldVisitEachCodeClass()
24 | {
25 | var project = DTETransformer.BuildDteProject(new Type[]
26 | {
27 | typeof(M),
28 | typeof(N)
29 | }, projectName: "NamespaceTraverserTests");
30 |
31 | int callCount = 0;
32 | var expectedNames = new string[] { "M", "N" };
33 | ProjectItem projectItem;
34 |
35 | if (TryGetSingle(project.ProjectItems.GetEnumerator(), out projectItem))
36 | {
37 | foreach (CodeNamespace ns in projectItem.FileCodeModel.CodeElements)
38 | new NamespaceTraverser(ns, (c) => { Assert.AreEqual(expectedNames[callCount++], c.Name); });
39 | }
40 |
41 | Assert.AreEqual(2, callCount);
42 | }
43 |
44 | private bool TryGetSingle(IEnumerator enumerator, out T item) where T: class
45 | {
46 | enumerator.MoveNext();
47 | item = (T)enumerator.Current;
48 | return !enumerator.MoveNext();
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/T4TS.Tests/Traversal/ProjectTraversalTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using T4TS.Tests.Utils;
4 | using T4TS.Tests.Traversal.Models;
5 | using T4TS.Example.Models;
6 | using EnvDTE;
7 | using Moq;
8 |
9 | namespace T4TS.Tests.Traversal
10 | {
11 | [TestClass]
12 | public class ProjectTraversalTests
13 | {
14 | [TestMethod]
15 | public void ShouldVisitEachNamespace()
16 | {
17 | var proj = DTETransformer.BuildDteProject(new Type[]
18 | {
19 | typeof(LocalModel),
20 | typeof(ModelFromDifferentProject)
21 | }, projectName: "proj");
22 |
23 | int callCount = 0;
24 | var expectedNames = new string[] { "T4TS.Tests.Traversal.Models", "T4TS.Example.Models" };
25 |
26 | new ProjectTraverser(proj, (ns) => { Assert.AreEqual(expectedNames[callCount++], ns.Name); });
27 |
28 | Assert.AreEqual(2, callCount);
29 | }
30 |
31 | [TestMethod]
32 | public void ShouldVisitSubProjectItems()
33 | {
34 | var subProjItem = DTETransformer.BuildDteProjectItem(new Type[]
35 | {
36 | typeof(ModelFromDifferentProject)
37 | }, projectItemName: "subProj");
38 |
39 | var moqSubProjectItems = new Mock();
40 | moqSubProjectItems.Setup(x => x.GetEnumerator()).Returns(() => new[] { subProjItem }.GetEnumerator());
41 |
42 | var proj = DTETransformer.BuildDteProject(new Type[]
43 | {
44 | typeof(LocalModel)
45 | }, projectName: "proj", subProjectItems: moqSubProjectItems.Object);
46 |
47 | int callCount = 0;
48 | var expectedNames = new string[] { "T4TS.Tests.Traversal.Models", "T4TS.Example.Models" };
49 |
50 | new ProjectTraverser(proj, (ns) => { Assert.AreEqual(expectedNames[callCount++], ns.Name); });
51 |
52 | Assert.AreEqual(2, callCount);
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/T4TS.Tests/TypeContext/TypeContextTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using System.Collections.Generic;
4 |
5 | namespace T4TS.Tests
6 | {
7 | [TestClass]
8 | public class TypeContextTests
9 | {
10 | [TestMethod]
11 | public void ShouldSupportDatetimesAsNativeDates()
12 | {
13 | var context = new TypeContext(new Settings
14 | {
15 | UseNativeDates = true
16 | });
17 |
18 | var resolvedType = context.GetTypeScriptType(typeof(DateTime).FullName);
19 | Assert.IsInstanceOfType(resolvedType, typeof(DateTimeType));
20 | }
21 |
22 | [TestMethod]
23 | public void ShouldSupportDatetimesAsStrings()
24 | {
25 | var context = new TypeContext(new Settings
26 | {
27 | UseNativeDates = false
28 | });
29 |
30 | var resolvedType = context.GetTypeScriptType(typeof(DateTime).FullName);
31 | Assert.IsInstanceOfType(resolvedType, typeof(StringType));
32 | }
33 |
34 | [TestMethod]
35 | public void ShouldSupportDatetimeOffsetAsNativeDates()
36 | {
37 | var context = new TypeContext(new Settings
38 | {
39 | UseNativeDates = true
40 | });
41 |
42 | var resolvedType = context.GetTypeScriptType(typeof(DateTimeOffset).FullName);
43 | Assert.IsInstanceOfType(resolvedType, typeof(DateTimeType));
44 | }
45 |
46 | [TestMethod]
47 | public void ShouldSupportDatetimeOffsetAsStrings()
48 | {
49 | var context = new TypeContext(new Settings
50 | {
51 | UseNativeDates = false
52 | });
53 |
54 | var resolvedType = context.GetTypeScriptType(typeof(DateTimeOffset).FullName);
55 | Assert.IsInstanceOfType(resolvedType, typeof(StringType));
56 | }
57 |
58 | [TestMethod]
59 | public void ShouldSupportNumberTypes()
60 | {
61 | var inputTypes = new [] {
62 | typeof(byte),
63 | typeof(sbyte),
64 | typeof(short),
65 | typeof(ushort),
66 | typeof(int),
67 | typeof(uint),
68 | typeof(long),
69 | typeof(ulong),
70 | typeof(float),
71 | typeof(decimal),
72 | typeof(double)
73 | };
74 |
75 | var context = new TypeContext(new Settings());
76 | var expectedType = typeof(NumberType);
77 |
78 | foreach (var type in inputTypes)
79 | {
80 | var resolvedType = context.GetTypeScriptType(type.FullName);
81 | Assert.IsInstanceOfType(resolvedType, expectedType);
82 | }
83 | }
84 |
85 | [TestMethod]
86 | public void ShouldSupportIEnumerableTypes()
87 | {
88 | var context = new TypeContext(new Settings());
89 |
90 | var resolvedType = context.GetTypeScriptType(typeof(IEnumerable).FullName);
91 | Assert.IsInstanceOfType(resolvedType, typeof(ArrayType));
92 |
93 | resolvedType = context.GetTypeScriptType("System.Collections.Generic.IEnumerable");
94 | Assert.IsInstanceOfType(resolvedType, typeof(ArrayType));
95 | }
96 |
97 | [TestMethod]
98 | public void ShouldSupportDicionaryTypes()
99 | {
100 | var context = new TypeContext(new Settings());
101 |
102 | var resolvedType = context.GetTypeScriptType(typeof(Dictionary).FullName);
103 | Assert.IsInstanceOfType(resolvedType, typeof(DictionaryType));
104 |
105 | resolvedType = context.GetTypeScriptType("System.Collections.Generic.Dictionary");
106 | Assert.IsInstanceOfType(resolvedType, typeof(DictionaryType));
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/T4TS.Tests/Utils/OutputFor.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Collections.ObjectModel;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Text.RegularExpressions;
8 | using System.Threading.Tasks;
9 |
10 | namespace T4TS.Tests.Utils
11 | {
12 | class OutputFor
13 | {
14 | readonly IReadOnlyCollection Types;
15 | public Settings Settings { get; private set; }
16 |
17 | public OutputFor(params Type[] types)
18 | {
19 | this.Types = new ReadOnlyCollection(types);
20 | this.Settings = new Settings();
21 | }
22 |
23 | public OutputFor With(Settings settings)
24 | {
25 | this.Settings = settings;
26 | return this;
27 | }
28 |
29 | public void ToEqual(string expectedOutput)
30 | {
31 | var generatedOutput = GenerateOutput();
32 | Assert.AreEqual(Normalize(expectedOutput), Normalize(generatedOutput));
33 | }
34 |
35 | private string GenerateOutput()
36 | {
37 | var solution = DTETransformer.BuildDteSolution(this.Types.ToArray());
38 | var generator = new CodeTraverser(solution, this.Settings);
39 | var data = generator.GetAllInterfaces().ToList();
40 |
41 | return OutputFormatter.GetOutput(data, this.Settings);
42 | }
43 |
44 | static string Normalize(string output)
45 | {
46 | return Regex.Replace(output, @"\r\n|\n\r|\n|\r", "\n").Trim();
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/T4TS.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/T4TS.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Example", "T4TS.Example\T4TS.Example.csproj", "{51E03259-D166-4DA9-8D55-1FA7BDE922ED}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS", "T4TS\T4TS.csproj", "{2B9CFEA6-586A-4E3B-8575-79447D5DC086}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Attributes", "T4TS.Attributes\T4TS.Attributes.csproj", "{AF50A5E0-791D-47D4-91FE-56A7CE4577EB}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Tests", "T4TS.Tests\T4TS.Tests.csproj", "{93F7F024-CE32-476E-995A-0B6AA5A649F3}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "T4TS.Example.Models", "T4TS.Example.Models\T4TS.Example.Models.csproj", "{93EE0391-DB26-40CC-A613-6CA32E3EEB18}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {51E03259-D166-4DA9-8D55-1FA7BDE922ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {51E03259-D166-4DA9-8D55-1FA7BDE922ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {51E03259-D166-4DA9-8D55-1FA7BDE922ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {51E03259-D166-4DA9-8D55-1FA7BDE922ED}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {2B9CFEA6-586A-4E3B-8575-79447D5DC086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {2B9CFEA6-586A-4E3B-8575-79447D5DC086}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {2B9CFEA6-586A-4E3B-8575-79447D5DC086}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {2B9CFEA6-586A-4E3B-8575-79447D5DC086}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {AF50A5E0-791D-47D4-91FE-56A7CE4577EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {AF50A5E0-791D-47D4-91FE-56A7CE4577EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {AF50A5E0-791D-47D4-91FE-56A7CE4577EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {AF50A5E0-791D-47D4-91FE-56A7CE4577EB}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {93F7F024-CE32-476E-995A-0B6AA5A649F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {93F7F024-CE32-476E-995A-0B6AA5A649F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {93F7F024-CE32-476E-995A-0B6AA5A649F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {93F7F024-CE32-476E-995A-0B6AA5A649F3}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {93EE0391-DB26-40CC-A613-6CA32E3EEB18}.Release|Any CPU.Build.0 = Release|Any CPU
40 | EndGlobalSection
41 | GlobalSection(SolutionProperties) = preSolution
42 | HideSolutionNode = FALSE
43 | EndGlobalSection
44 | EndGlobal
45 |
--------------------------------------------------------------------------------
/T4TS/Outputs/InterfaceOutputAppender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | public class InterfaceOutputAppender : OutputAppender
10 | {
11 | private bool InGlobalModule { get; set; }
12 |
13 | public InterfaceOutputAppender(StringBuilder output, int baseIndentation, Settings settings, bool inGlobalModule)
14 | : base(output, baseIndentation, settings)
15 | {
16 | this.InGlobalModule = inGlobalModule;
17 | }
18 |
19 | public override void AppendOutput(TypeScriptInterface tsInterface)
20 | {
21 | BeginInterface(tsInterface);
22 |
23 | AppendMembers(tsInterface);
24 |
25 | if (tsInterface.IndexedType != null)
26 | AppendIndexer(tsInterface);
27 |
28 | EndInterface();
29 | }
30 |
31 | private void AppendMembers(TypeScriptInterface tsInterface)
32 | {
33 | var appender = new MemberOutputAppender(Output, BaseIndentation + 4, Settings);
34 | foreach (var member in tsInterface.Members)
35 | appender.AppendOutput(member);
36 | }
37 |
38 | private void BeginInterface(TypeScriptInterface tsInterface)
39 | {
40 | AppendIndentedLine("/** Generated from " + tsInterface.FullName + " **/");
41 |
42 | if (InGlobalModule)
43 | AppendIndented("interface " + tsInterface.Name);
44 | else
45 | AppendIndented("export interface " + tsInterface.Name);
46 |
47 | if (!string.IsNullOrEmpty(tsInterface.Extends))
48 | Output.Append(" extends " + tsInterface.Extends);
49 | else if (tsInterface.Parent != null)
50 | Output.Append(" extends " + (tsInterface.Parent.Module.IsGlobal ? "" : tsInterface.Parent.Module.QualifiedName + ".") + tsInterface.Parent.Name);
51 |
52 | Output.AppendLine(" {");
53 | }
54 |
55 | private void EndInterface()
56 | {
57 | AppendIndentedLine("}");
58 | }
59 |
60 | private void AppendIndexer(TypeScriptInterface tsInterface)
61 | {
62 | AppendIndendation();
63 | Output.AppendFormat(" [index: number]: {0};", tsInterface.IndexedType);
64 | Output.AppendLine();
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/T4TS/Outputs/MemberOutputAppender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | public class MemberOutputAppender : OutputAppender
10 | {
11 | public MemberOutputAppender(StringBuilder output, int baseIndentation, Settings settings)
12 | : base(output, baseIndentation, settings)
13 | {
14 | }
15 |
16 | public override void AppendOutput(TypeScriptInterfaceMember member)
17 | {
18 | AppendIndendation();
19 |
20 | bool isOptional = member.Optional;
21 | string type = member.Type.ToString();
22 |
23 | if (member.Type is BoolType)
24 | {
25 | if (Settings.CompatibilityVersion != null && Settings.CompatibilityVersion < new Version(0, 9, 0))
26 | type = "bool";
27 | else
28 | type = "boolean";
29 | }
30 |
31 | Output.AppendFormat("{0}{1}: {2}",
32 | member.Name,
33 | (isOptional ? "?" : ""),
34 | type
35 | );
36 |
37 | Output.AppendLine(";");
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/T4TS/Outputs/ModuleOutputAppender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | public class ModuleOutputAppender : OutputAppender
10 | {
11 | public ModuleOutputAppender(StringBuilder output, int baseIndentation, Settings settings)
12 | : base(output, baseIndentation, settings)
13 | {
14 | }
15 |
16 | public override void AppendOutput(TypeScriptModule module)
17 | {
18 | BeginModule(module);
19 |
20 | var interfaceAppender = new InterfaceOutputAppender(Output, BaseIndentation + 4, Settings, module.IsGlobal);
21 | foreach (var tsInterface in module.Interfaces)
22 | interfaceAppender.AppendOutput(tsInterface);
23 |
24 | EndModule(module);
25 | }
26 |
27 | private void BeginModule(TypeScriptModule module)
28 | {
29 | if (module.IsGlobal)
30 | {
31 | Output.AppendLine("// -- Begin global interfaces");
32 | }
33 | else
34 | {
35 | if (Settings.CompatibilityVersion != null && Settings.CompatibilityVersion < new Version(0, 9, 0))
36 | Output.Append("module ");
37 | else
38 | Output.Append("declare module ");
39 |
40 | Output.Append(module.QualifiedName);
41 | Output.AppendLine(" {");
42 | }
43 | }
44 |
45 | private void EndModule(TypeScriptModule module)
46 | {
47 | if (module.IsGlobal)
48 | Output.AppendLine("// -- End global interfaces");
49 | else
50 | Output.AppendLine("}");
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/T4TS/Outputs/OutputAppender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace T4TS
9 | {
10 | public abstract class OutputAppender where TSegment: class
11 | {
12 | protected StringBuilder Output { get; private set; }
13 | protected int BaseIndentation { get; private set; }
14 | protected Settings Settings { get; private set; }
15 |
16 | public OutputAppender(StringBuilder output, int baseIndentation, Settings settings)
17 | {
18 | if (output == null)
19 | throw new ArgumentNullException("output");
20 |
21 | if (settings == null)
22 | throw new ArgumentNullException("settings");
23 |
24 | this.Output = output;
25 | this.BaseIndentation = baseIndentation;
26 | this.Settings = settings;
27 | }
28 |
29 | public abstract void AppendOutput(TSegment segment);
30 |
31 | protected void AppendIndented(string text)
32 | {
33 | AppendIndendation();
34 | Output.Append(text);
35 | }
36 |
37 | protected void AppendIndentedLine(string line)
38 | {
39 | AppendIndendation();
40 | Output.AppendLine(line);
41 | }
42 |
43 | protected void AppendIndendation()
44 | {
45 | Output.Append(' ', BaseIndentation);
46 | }
47 |
48 | public override string ToString()
49 | {
50 | return Output.ToString();
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/T4TS/Outputs/OutputFormatter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | public static class OutputFormatter
10 | {
11 | public static string GetOutput(List modules, Settings settings)
12 | {
13 | var output = new StringBuilder();
14 |
15 | output.AppendLine("/****************************************************************************");
16 | output.AppendLine(" Generated by T4TS.tt - don't make any changes in this file");
17 | output.AppendLine("****************************************************************************/");
18 |
19 | var moduleAppender = new ModuleOutputAppender(output, 0, settings);
20 | foreach (var module in modules)
21 | {
22 | output.AppendLine();
23 | moduleAppender.AppendOutput(module);
24 | }
25 |
26 | return output.ToString();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/T4TS/Outputs/TypeScriptInterface.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using EnvDTE;
7 |
8 | namespace T4TS
9 | {
10 | [System.Diagnostics.DebuggerDisplay("TypeScriptInterface {FullName}")]
11 | public class TypeScriptInterface
12 | {
13 | public string Name { get; set; }
14 | public string FullName { get; set; }
15 | public string Extends { get; set; }
16 |
17 | public List Members { get; set; }
18 | public TypescriptType IndexedType { get; set; }
19 | public TypeScriptInterface Parent { get; set; }
20 | public TypeScriptModule Module { get; set; }
21 |
22 | public TypeScriptInterface()
23 | {
24 | Members = new List();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/T4TS/Outputs/TypeScriptInterfaceAttributeValues.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace T4TS
4 | {
5 | public class TypeScriptInterfaceAttributeValues
6 | {
7 | public string Module { get; set; }
8 | public string Name { get; set; }
9 | public string NamePrefix { get; set; }
10 | public string Extends { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/T4TS/Outputs/TypeScriptInterfaceMember.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace T4TS
7 | {
8 | public class TypeScriptInterfaceMember
9 | {
10 | public string Name { get; set; }
11 | public TypescriptType Type { get; set; }
12 | public bool Optional { get; set; }
13 | //public string FullName { get; set; }
14 | public bool Ignore { get; set; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/T4TS/Outputs/TypeScriptMemberAttributeValues.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | public class TypeScriptMemberAttributeValues
10 | {
11 | public string Name { get; set; }
12 | public bool Optional { get; set; }
13 | public string Type { get; set; }
14 | public bool CamelCase { get; set; }
15 | public bool Ignore { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/T4TS/Outputs/TypeScriptModule.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | [System.Diagnostics.DebuggerDisplay("TSModule {QualifiedName}")]
10 | public class TypeScriptModule
11 | {
12 | public string QualifiedName { get; set; }
13 | public List Interfaces { get; set; }
14 |
15 | ///
16 | /// Returns true if this is the global namespace (ie. no module name)
17 | ///
18 | public bool IsGlobal
19 | {
20 | get { return string.IsNullOrWhiteSpace(QualifiedName); }
21 | }
22 |
23 | public TypeScriptModule()
24 | {
25 | Interfaces = new List();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/T4TS/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("T4TS.Generator")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("T4TS.Generator")]
13 | [assembly: AssemblyCopyright("Copyright © 2012")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("d17c2cca-0625-42ee-92a1-75295fca26bb")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/T4TS/Settings.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace T4TS
8 | {
9 | public class Settings
10 | {
11 | ///
12 | /// The default module of the generated interface, if not specified by the TypeScriptInterfaceAttribute
13 | ///
14 | public string DefaultModule { get; set; }
15 |
16 | ///
17 | /// The default value for Optional, if not specified by the TypeScriptMemberAttribute
18 | ///
19 | public bool DefaultOptional { get; set; }
20 |
21 | ///
22 | /// The default value for the CamelCase flag for an interface member name, if not specified by the TypeScriptMemberAttribute
23 | ///
24 | public bool DefaultCamelCaseMemberNames { get; set; }
25 |
26 | ///
27 | /// The default string to prefix interface names with. For instance, you might want to prefix the names with an "I" to get conventional interface names.
28 | ///
29 | public string DefaultInterfaceNamePrefix { get; set; }
30 |
31 | ///
32 | /// The version of Typescript that is targeted
33 | ///
34 | public Version CompatibilityVersion { get; set; }
35 |
36 | ///
37 | /// If true translates System.DateTime to native date
38 | ///
39 | public bool UseNativeDates { get; set; }
40 |
41 | public static Settings Parse(Dictionary settingsValues)
42 | {
43 | // Read settings from T4TS.tt.settings.tt
44 | return new Settings
45 | {
46 | DefaultModule = ParseSettingReferenceType(settingsValues, "DefaultModule", s => s as string, "T4TS"),
47 | DefaultOptional = ParseSettingNullableType(settingsValues, "DefaultOptional", false),
48 | DefaultCamelCaseMemberNames = ParseSettingNullableType(settingsValues, "DefaultCamelCaseMemberNames", false),
49 | DefaultInterfaceNamePrefix = ParseSettingReferenceType(settingsValues, "DefaultInterfaceNamePrefix", s => s as string, string.Empty),
50 | CompatibilityVersion = ParseSettingReferenceType(settingsValues, "CompatibilityVersion", v => v as Version, new Version(0, 9, 1, 1)),
51 | UseNativeDates = ParseSettingNullableType(settingsValues, "UseNativeDates", false)
52 | };
53 | }
54 |
55 | private static T ParseSettingReferenceType(Dictionary settingsValues, string key, Func