├── TypescriptSyntaxPaste
├── Key.snk
├── VSIX
│ ├── Resources
│ │ └── ToolOptions.ico
│ └── PasteTextviewCreationListener.cs
├── Patch
│ ├── Patch.cs
│ ├── ArrayInitReturnForYieldPatch.cs
│ ├── GenericConstrantsPatch.cs
│ ├── InnerTypeDeclarationPatch.cs
│ └── FieldInitializePatch.cs
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ └── AssemblyInfo.cs
├── Contract
│ ├── IBaseExtended.cs
│ ├── ITranslationVisitor.cs
│ └── ITypeParameterConstraint.cs
├── Constants
│ ├── ModifierConstants.cs
│ ├── PredefinedTypeConstants.cs
│ ├── TranslationSyntaxConstants.cs
│ └── OperatorConstants.cs
├── vss-extension.json
├── ISettingStore.cs
├── Translation
│ ├── NameTranslation.cs
│ ├── InstanceExpressionTranslation.cs
│ ├── CSharpSyntaxTranslation.cs
│ ├── ExpressionTranslation.cs
│ ├── MemberDeclarationTranslation.cs
│ ├── GenericTranslation.cs
│ ├── StatementTranslation.cs
│ ├── SimpleBaseTypeTranslation.cs
│ ├── TypeTranslation.cs
│ ├── ThisExpressionTranslation.cs
│ ├── LiteralExpressionTranslation.cs
│ ├── PointerTypeTranslation.cs
│ ├── BaseExpressionTranslation.cs
│ ├── ClassTranslationTemplate.cs
│ ├── SwitchLabelTranslation.cs
│ ├── BreakStatementTranslation.cs
│ ├── EmptyStatementTranslation.cs
│ ├── AttributeListTranslation.cs
│ ├── QueryExpressionTranslation.cs
│ ├── ContinueStatementTranslation.cs
│ ├── BracketedArgumentListTranslation.cs
│ ├── CatchDeclarationTranslation.cs
│ ├── DefaultSwitchLabelTranslation.cs
│ ├── EnumMemberDeclarationTranslation.cs
│ ├── BracketedParameterListTranslation.cs
│ ├── OmittedArraySizeExpressionTranslation.cs
│ ├── TypeParameterConstraintTranslation.cs
│ ├── BaseTypeTranslation.cs
│ ├── ClassOrStructConstraintTranslation.cs
│ ├── BaseArgumentListTranslation.cs
│ ├── InterpolatedStringExpressionTranslation.cs
│ ├── GotoStatementTranslation.cs
│ ├── NullableTypeTranslation.cs
│ ├── ElseClauseTranslation.cs
│ ├── TypeConstraintTranslation.cs
│ ├── DefaultExpressionTranslation.cs
│ ├── ExpressionStatementTranslation.cs
│ ├── FinallyClauseTranslation.cs
│ ├── CaseSwitchLabelTranslation.cs
│ ├── AwaitStatementTranslation.cs
│ ├── CheckedExpressionTranslation.cs
│ ├── MemberBindingExpressionTranslation.cs
│ ├── LocalDeclarationStatementTranslation.cs
│ ├── ParenthesizedExpressionTranslation.cs
│ ├── TypeArgumentListTranslation.cs
│ ├── ArgumentListTranslation.cs
│ ├── PrefixUnaryExpressionTranslation.cs
│ ├── PostfixUnaryExpressionTranslation.cs
│ ├── ArrayRankSpecifierTranslation.cs
│ ├── BaseParameterListTranslation.cs
│ ├── SyntaxListTranslation.cs
│ ├── TypeParameterTranslation.cs
│ ├── NameOfExpressionTranslation.cs
│ ├── TokenTranslation.cs
│ ├── ClassTranslationTemplate.tt
│ ├── ImplicitArrayCreationExpressionTranslation.cs
│ ├── CastExpressionTranslation.cs
│ ├── LockStatementTranslation.cs
│ ├── DoStatementTranslation.cs
│ ├── WhileStatementTranslation.cs
│ ├── EqualsValueClauseTranslation.cs
│ ├── BaseTypeDeclarationTranslation.cs
│ ├── EnumDeclarationTranslation.cs
│ ├── SimpleLambdaExpressionTranslation.cs
│ ├── ParenthesizedLambdaExpressionTranslation.cs
│ ├── ClassStructDeclarationTranslation.cs
│ ├── ConditionalAccessExpressionTranslation.cs
│ ├── ConstructorInitializerTranslation.cs
│ ├── FieldDeclarationTranslation.cs
│ ├── BlockTranslation.cs
│ ├── TypeParameterConstraintClauseTranslation.cs
│ ├── CatchClauseTranslation.cs
│ ├── InterfaceDeclarationTranslation.cs
│ ├── BasePropertyDeclarationTranslation.cs
│ ├── ConversionOperatorDeclarationTranslation.cs
│ ├── ConditionalExpressionTranslation.cs
│ ├── ReturnStatementTranslation.cs
│ ├── ElementAccessExpressionTranslation.cs
│ ├── AccessorListTranslation.cs
│ ├── LabeledStatementTranslation.cs
│ ├── SimpleNameTranslation.cs
│ ├── ClassDeclarationTranslation.cs
│ ├── ThrowStatementTranslation.cs
│ ├── ArrayTypeTranslation.cs
│ ├── SwitchSectionTranslation.cs
│ ├── NamespaceDeclarationTranslation.cs
│ ├── ParameterListTranslation.cs
│ ├── IfStatementTranslation.cs
│ ├── TypeOfExpressionTranslation.cs
│ ├── SwitchStatementTranslation.cs
│ ├── ForEachStatementTranslation.cs
│ ├── TypeParameterListTranslation.cs
│ ├── ArgumentTranslation.cs
│ ├── ArrayCreationExpressionTranslation.cs
│ ├── YieldStatementTranslation.cs
│ ├── StructDeclarationTranslation.cs
│ ├── SizeOfExpressionTranslation.cs
│ ├── ObjectCreationExpressionTranslation.cs
│ ├── QualifiedNameTranslation.cs
│ ├── SyntaxNodeExtensions.cs
│ ├── CompilationalUnitTranslation.cs
│ ├── ForStatementTranslation.cs
│ ├── OperatorDeclarationTranslation.cs
│ ├── VariableDeclarationTranslation.cs
│ ├── BaseMethodDeclarationTranslation.cs
│ ├── PropertyDeclarationTranslation.cs
│ ├── TypeDeclarationTranslation.cs
│ ├── InitializerExpressionTranslation.cs
│ ├── InvocationExpressionTranslation.cs
│ ├── SeparatedSyntaxListTranslation.cs
│ ├── MemberAccessExpressionTranslation.cs
│ ├── ConstructorDeclarationTranslation.cs
│ └── UsingStatementTranslation.cs
├── VirtualTranslation
│ ├── Delegates
│ │ ├── PredicateGenericNameTranslation.cs
│ │ ├── ComparisonGenericNameTranslation.cs
│ │ ├── ActionTypeGenericNameTranslation.cs
│ │ ├── BaseFunctionGenericNameTranslation.cs
│ │ └── FunctionTypeGenericNameTranslation.cs
│ └── VirtualTokenTranslation.cs
├── TypeNameReplacement.cs
├── AddIPrefixInterfaceDeclaration.cs
├── OptionalInterfaceProperties.cs
├── app.config
├── source.extension.vsixmanifest
├── MakeMemberCamelCase.cs
└── SyntaxTranslationFactory.cs
├── TypescriptSyntaxPaste.Console
├── App.config
├── Properties
│ └── AssemblyInfo.cs
└── Program.cs
├── TypescriptSyntaxPaste.Tests
├── GeneralTestCases
│ └── Case1.cs
├── app.config
├── Properties
│ └── AssemblyInfo.cs
├── ConvertHelper.cs
└── ThrowStatementTests.cs
├── README.md
├── TypescriptSyntaxPasteSolution.sln
└── .gitattributes
/TypescriptSyntaxPaste/Key.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nhabuiduc/TypescriptSyntaxPaste/HEAD/TypescriptSyntaxPaste/Key.snk
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VSIX/Resources/ToolOptions.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nhabuiduc/TypescriptSyntaxPaste/HEAD/TypescriptSyntaxPaste/VSIX/Resources/ToolOptions.ico
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Console/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Patch/Patch.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 RoslynTypeScript.Patch
8 | {
9 | public abstract class Patch
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Tests/GeneralTestCases/Case1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 |
4 | namespace TypescriptSyntaxPaste.Tests.GeneralTestCases
5 | {
6 | [TestClass]
7 | public class Case1
8 | {
9 | [TestMethod]
10 | public void ConvertOk()
11 | {
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Contract/IBaseExtended.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using RoslynTypeScript.Translation;
7 |
8 | namespace RoslynTypeScript.Contract
9 | {
10 | public interface IBaseExtended
11 | {
12 | BaseListTranslation BaseList { get; set; }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Constants/ModifierConstants.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 RoslynTypeScript
8 | {
9 | public class ModifierConstants
10 | {
11 | public const string Private = "private";
12 | public const string Static = "static";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Constants/PredefinedTypeConstants.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 RoslynTypeScript
8 | {
9 | public class PredefinedTypeConstants
10 | {
11 | public const string Any = "any";
12 | public const string Number = "number";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Contract/ITranslationVisitor.cs:
--------------------------------------------------------------------------------
1 | using RoslynTypeScript.Translation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.Contract
9 | {
10 | public interface ITranslationVisitor
11 | {
12 | void Visit(SyntaxTranslation translation);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/vss-extension.json:
--------------------------------------------------------------------------------
1 | {
2 | "manifestVersion": 1,
3 | "id": "TypescriptSyntaxPaste",
4 | "version": "1.2.5",
5 | "name": "Typescript Syntax Paste",
6 | "publisher": "NhaBuiDuc",
7 | "tags": [
8 | "Typescript",
9 | "Conversion"
10 | ],
11 | "targets": [
12 | {
13 | "id": "Microsoft.VisualStudio.Services"
14 | }
15 | ]
16 | }
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/ISettingStore.cs:
--------------------------------------------------------------------------------
1 | using TypescriptSyntaxPaste.VSIX;
2 |
3 | namespace TypescriptSyntaxPaste
4 | {
5 | public interface ISettingStore
6 | {
7 | bool AddIPrefixInterfaceDeclaration { get; set; }
8 | bool IsConvertListToArray { get; set; }
9 | bool IsConvertMemberToCamelCase { get; set; }
10 | bool IsConvertToInterface { get; set; }
11 | bool IsInterfaceOptionalProperties { get; set; }
12 | TypeNameReplacementData[] ReplacedTypeNameArray { get; set; }
13 | }
14 | }
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Constants/TranslationSyntaxConstants.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 RoslynTypeScript.Constants
8 | {
9 | public static class TC
10 | {
11 | public const string RefObjectName = "refObj";
12 | public const string IndexerGetName = "$get$";
13 | public const string IndexerSetName = "$set$";
14 | public const string YieldResultName = "__result";
15 | public const string IStruct = "IStruct";
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/NameTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class NameTranslation : TypeTranslation
12 | {
13 | public NameTranslation() { }
14 |
15 | public NameTranslation(NameSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
16 | {
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/InstanceExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript
10 | {
11 | public abstract class InstanceExpressionTranslation :ExpressionTranslation
12 | {
13 | public InstanceExpressionTranslation(InstanceExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
14 | {
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CSharpSyntaxTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.CodeAnalysis;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class CSharpSyntaxTranslation :SyntaxTranslation
12 | {
13 | public CSharpSyntaxTranslation() { }
14 | public CSharpSyntaxTranslation(SyntaxNode syntax, SyntaxTranslation parent) : base(syntax, parent)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class ExpressionTranslation : CSharpSyntaxTranslation
12 | {
13 | public ExpressionTranslation() { }
14 | public ExpressionTranslation(ExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Contract/ITypeParameterConstraint.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Contract
10 | {
11 | public interface ITypeParameterConstraint
12 | {
13 | TypeParameterListTranslation TypeParameterList { get; set; }
14 |
15 | SyntaxListTranslation ConstraintClauses { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/MemberDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.Translation
9 | {
10 | public abstract class MemberDeclarationTranslation : CSharpSyntaxTranslation
11 | {
12 | public MemberDeclarationTranslation() { }
13 | public MemberDeclarationTranslation(MemberDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
14 | {
15 |
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/GenericTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.Translation
9 | {
10 | public class GenericTranslation : CSharpSyntaxTranslation
11 | {
12 |
13 | public GenericTranslation(SyntaxNode syntax, SyntaxTranslation parent) : base(syntax, parent)
14 | {
15 | }
16 |
17 | protected override string InnerTranslate()
18 | {
19 | return Syntax.ToString();
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/StatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class StatementTranslation : CSharpSyntaxTranslation
12 | {
13 | public StatementTranslation()
14 | {
15 | }
16 |
17 | public StatementTranslation(StatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
18 | {
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SimpleBaseTypeTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class SimpleBaseTypeTranslation : BaseTypeTranslation
12 | {
13 | public new SimpleBaseTypeSyntax Syntax
14 | {
15 | get { return (SimpleBaseTypeSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public SimpleBaseTypeTranslation() { }
19 | public SimpleBaseTypeTranslation(SimpleBaseTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | this.Syntax = syntax;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VirtualTranslation/Delegates/PredicateGenericNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using RoslynTypeScript.Translation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.VirtualTranslation
9 | {
10 | public class PredicateGenericNameTranslation : BaseFunctionGenericNameTranslation
11 | {
12 | public PredicateGenericNameTranslation(GenericNameTranslation genericNameTranslation) :base(genericNameTranslation)
13 | {
14 | }
15 |
16 | protected override string InnerTranslate()
17 | {
18 | var firstParam = genericNameTranslation.TypeArgumentList.Arguments.GetEnumerable().First();
19 | return $"(_:{firstParam.Translate()})=>boolean";
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class TypeTranslation : ExpressionTranslation
12 | {
13 | public TypeTranslation() { }
14 | public TypeTranslation(TypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
15 | {
16 | }
17 |
18 | public bool ActAsTypeParameter { get; set; }
19 |
20 | public virtual bool IsPrimitive
21 | {
22 | get { return false; }
23 | }
24 |
25 | public virtual string GetTypeIgnoreGeneric()
26 | {
27 | return this.Translate();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ThisExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ThisExpressionTranslation : InstanceExpressionTranslation
12 | {
13 | public new ThisExpressionSyntax Syntax
14 | {
15 | get { return (ThisExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ThisExpressionTranslation(ThisExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
19 | {
20 | }
21 |
22 | protected override string InnerTranslate()
23 | {
24 | return Syntax.ToString();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/LiteralExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class LiteralExpressionTranslation : ExpressionTranslation
12 | {
13 | public new LiteralExpressionSyntax Syntax
14 | {
15 | get { return (LiteralExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public LiteralExpressionTranslation(LiteralExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
19 | {
20 | }
21 |
22 | protected override string InnerTranslate()
23 | {
24 | return Syntax.ToString();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VirtualTranslation/VirtualTokenTranslation.cs:
--------------------------------------------------------------------------------
1 | using RoslynTypeScript.Translation;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.VirtualTranslation
9 | {
10 | public class VirtualTokenTranslation :TokenTranslation
11 | {
12 | public string TokenStr { get; set; }
13 |
14 | protected override string InnerTranslate()
15 | {
16 | return TokenStr;
17 | }
18 |
19 | public override bool IsEmpty
20 | {
21 | get
22 | {
23 | return TokenStr == string.Empty;
24 | }
25 | }
26 |
27 | public static VirtualTokenTranslation SemicolonToken
28 | {
29 | get { return new VirtualTokenTranslation { TokenStr = ";" }; }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/PointerTypeTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class PointerTypeTranslation : TypeTranslation
12 | {
13 | public new PointerTypeSyntax Syntax
14 | {
15 | get { return (PointerTypeSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public PointerTypeTranslation() { }
20 | public PointerTypeTranslation(PointerTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VirtualTranslation/Delegates/ComparisonGenericNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using RoslynTypeScript.Translation;
7 |
8 | namespace RoslynTypeScript.VirtualTranslation.Delegates
9 | {
10 | public class ComparisonGenericNameTranslation : BaseFunctionGenericNameTranslation
11 | {
12 | public ComparisonGenericNameTranslation(GenericNameTranslation genericNameTranslation) : base(genericNameTranslation)
13 | {
14 | }
15 |
16 | protected override string InnerTranslate()
17 | {
18 | var firstParam = genericNameTranslation.TypeArgumentList.Arguments.GetEnumerable().First();
19 | string firstParamStr = firstParam.Translate();
20 | return $"(_:{firstParamStr}, __:{firstParamStr})=> number";
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BaseExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BaseExpressionTranslation : ExpressionTranslation
12 | {
13 | public new BaseExpressionSyntax Syntax
14 | {
15 | get { return (BaseExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BaseExpressionTranslation() { }
20 | public BaseExpressionTranslation(BaseExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | }
23 |
24 | protected override string InnerTranslate()
25 | {
26 | return "super";
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ClassTranslationTemplate.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class AttributeListTranslation : SyntaxTranslation
12 | {
13 | public new AttributeListSyntax Syntax
14 | {
15 | get { return (AttributeListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public AttributeListTranslation(){}
20 | public AttributeListTranslation(AttributeListSyntax syntax, SyntaxTranslation parent): base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SwitchLabelTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class SwitchLabelTranslation : CSharpSyntaxTranslation
12 | {
13 | public new SwitchLabelSyntax Syntax
14 | {
15 | get { return (SwitchLabelSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public SwitchLabelTranslation() { }
20 | public SwitchLabelTranslation(SwitchLabelSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BreakStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BreakStatementTranslation : StatementTranslation
12 | {
13 | public new BreakStatementSyntax Syntax
14 | {
15 | get { return (BreakStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BreakStatementTranslation() { }
20 | public BreakStatementTranslation(BreakStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/EmptyStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class EmptyStatementTranslation : StatementTranslation
12 | {
13 | public new EmptyStatementSyntax Syntax
14 | {
15 | get { return (EmptyStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public EmptyStatementTranslation() { }
20 | public EmptyStatementTranslation(EmptyStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/AttributeListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class AttributeListTranslation : CSharpSyntaxTranslation
12 | {
13 | public new AttributeListSyntax Syntax
14 | {
15 | get { return (AttributeListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public AttributeListTranslation() { }
20 | public AttributeListTranslation(AttributeListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return $" /*{Syntax.ToString()}*/";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/QueryExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class QueryExpressionTranslation : ExpressionTranslation
12 | {
13 | public new QueryExpressionSyntax Syntax
14 | {
15 | get { return (QueryExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public QueryExpressionTranslation() { }
20 | public QueryExpressionTranslation(QueryExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ContinueStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ContinueStatementTranslation : StatementTranslation
12 | {
13 | public new ContinueStatementSyntax Syntax
14 | {
15 | get { return (ContinueStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ContinueStatementTranslation() { }
20 | public ContinueStatementTranslation(ContinueStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | }
23 |
24 | protected override string InnerTranslate()
25 | {
26 | return Syntax.ToString();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BracketedArgumentListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BracketedArgumentListTranslation : BaseArgumentListTranslation
12 | {
13 | public new BracketedArgumentListSyntax Syntax
14 | {
15 | get { return (BracketedArgumentListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public BracketedArgumentListTranslation(BracketedArgumentListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
19 | {
20 |
21 | }
22 |
23 | protected override string InnerTranslate()
24 | {
25 | return $"[{Arguments.Translate()}]";
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CatchDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class CatchDeclarationTranslation : CSharpSyntaxTranslation
12 | {
13 | public new CatchDeclarationSyntax Syntax
14 | {
15 | get { return (CatchDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public CatchDeclarationTranslation() { }
20 | public CatchDeclarationTranslation(CatchDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return Syntax.ToString();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/DefaultSwitchLabelTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class DefaultSwitchLabelTranslation : SwitchLabelTranslation
12 | {
13 | public new DefaultSwitchLabelSyntax Syntax
14 | {
15 | get { return (DefaultSwitchLabelSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public DefaultSwitchLabelTranslation() { }
20 | public DefaultSwitchLabelTranslation(DefaultSwitchLabelSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/EnumMemberDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class EnumMemberDeclarationTranslation : MemberDeclarationTranslation
12 | {
13 | public new EnumMemberDeclarationSyntax Syntax
14 | {
15 | get { return (EnumMemberDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public EnumMemberDeclarationTranslation() { }
19 | public EnumMemberDeclarationTranslation(EnumMemberDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | }
22 |
23 |
24 | protected override string InnerTranslate()
25 | {
26 | return Syntax.ToString();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BracketedParameterListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BracketedParameterListTranslation : BaseParameterListTranslation
12 | {
13 | public new BracketedParameterListSyntax Syntax
14 | {
15 | get { return (BracketedParameterListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BracketedParameterListTranslation() { }
20 | public BracketedParameterListTranslation(BracketedParameterListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return Syntax.ToString();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/OmittedArraySizeExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class OmittedArraySizeExpressionTranslation : CSharpSyntaxTranslation
12 | {
13 | public new OmittedArraySizeExpressionSyntax Syntax
14 | {
15 | get { return (OmittedArraySizeExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public OmittedArraySizeExpressionTranslation() { }
19 | public OmittedArraySizeExpressionTranslation(OmittedArraySizeExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | }
22 |
23 | protected override string InnerTranslate()
24 | {
25 | return Syntax.ToString();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeParameterConstraintTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeParameterConstraintTranslation : CSharpSyntaxTranslation
12 | {
13 | public new TypeParameterConstraintSyntax Syntax
14 | {
15 | get { return (TypeParameterConstraintSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public TypeParameterConstraintTranslation() { }
20 | public TypeParameterConstraintTranslation(TypeParameterConstraintSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return Syntax.ToString();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BaseTypeTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BaseTypeTranslation : CSharpSyntaxTranslation
12 | {
13 | public new BaseTypeSyntax Syntax
14 | {
15 | get { return (BaseTypeSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BaseTypeTranslation() { }
20 | public BaseTypeTranslation(BaseTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | }
24 |
25 | public TypeTranslation Type { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return Type.ToString();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ClassOrStructConstraintTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ClassOrStructConstraintTranslation : TypeParameterConstraintTranslation
12 | {
13 | public new ClassOrStructConstraintSyntax Syntax
14 | {
15 | get { return (ClassOrStructConstraintSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ClassOrStructConstraintTranslation() { }
20 | public ClassOrStructConstraintTranslation(ClassOrStructConstraintSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return Syntax.ToString();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BaseArgumentListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class BaseArgumentListTranslation : CSharpSyntaxTranslation
12 | {
13 | public new BaseArgumentListSyntax Syntax
14 | {
15 | get { return (BaseArgumentListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BaseArgumentListTranslation() { }
20 | public BaseArgumentListTranslation(BaseArgumentListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Arguments = syntax.Arguments.Get(this);
23 | }
24 |
25 | public SeparatedSyntaxListTranslation Arguments { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/InterpolatedStringExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class InterpolatedStringExpressionTranslation : ExpressionTranslation
12 | {
13 | public new InterpolatedStringExpressionSyntax Syntax
14 | {
15 | get { return (InterpolatedStringExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public InterpolatedStringExpressionTranslation() { }
20 | public InterpolatedStringExpressionTranslation(InterpolatedStringExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 |
23 | }
24 |
25 | protected override string InnerTranslate()
26 | {
27 | return Syntax.ToString();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/GotoStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class GotoStatementTranslation : StatementTranslation
13 | {
14 | public new GotoStatementSyntax Syntax
15 | {
16 | get { return (GotoStatementSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public GotoStatementTranslation() { }
21 | public GotoStatementTranslation(GotoStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 |
24 | }
25 |
26 | public ExpressionTranslation Expression { get; set; }
27 |
28 | protected override string InnerTranslate()
29 | {
30 |
31 | return Syntax.ToString();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/NullableTypeTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class NullableTypeTranslation : TypeTranslation
12 | {
13 | public new NullableTypeSyntax Syntax
14 | {
15 | get { return (NullableTypeSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public NullableTypeTranslation() { }
20 | public NullableTypeTranslation(NullableTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | ElementType = syntax.ElementType.Get(this);
23 | }
24 |
25 | public TypeTranslation ElementType { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return ElementType.Translate();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ElseClauseTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ElseClauseTranslation : CSharpSyntaxTranslation
12 | {
13 | public new ElseClauseSyntax Syntax
14 | {
15 | get { return (ElseClauseSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ElseClauseTranslation() { }
20 | public ElseClauseTranslation(ElseClauseSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Statement = syntax.Statement.Get(this);
23 | }
24 |
25 | public StatementTranslation Statement { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $"else {Statement.Translate()}";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeConstraintTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeConstraintTranslation : TypeParameterConstraintTranslation
12 | {
13 | public new TypeConstraintSyntax Syntax
14 | {
15 | get { return (TypeConstraintSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public TypeConstraintTranslation() { }
20 | public TypeConstraintTranslation(TypeConstraintSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | }
24 |
25 | public TypeTranslation Type { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return Syntax.ToString();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/DefaultExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class DefaultExpressionTranslation : ExpressionTranslation
12 | {
13 | public new DefaultExpressionSyntax Syntax
14 | {
15 | get { return (DefaultExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public DefaultExpressionTranslation() { }
19 | public DefaultExpressionTranslation(DefaultExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Type = syntax.Type.Get(this);
22 | }
23 |
24 | public TypeTranslation Type { get; set; }
25 | protected override string InnerTranslate()
26 | {
27 | return Helper.GetDefaultValue(Type);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ExpressionStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ExpressionStatementTranslation : StatementTranslation
12 | {
13 | public new ExpressionStatementSyntax Syntax
14 | {
15 | get { return (ExpressionStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ExpressionTranslation Expression { get; set; }
19 | public ExpressionStatementTranslation(ExpressionStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Expression = syntax.Expression.Get(this);
22 | }
23 |
24 | protected override string InnerTranslate()
25 | {
26 | return string.Format("{0};", Expression.Translate());
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Constants/OperatorConstants.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 RoslynTypeScript.Constants
8 | {
9 | public static class OperatorConstants
10 | {
11 | public const string OperatorEquals = "==";
12 | public const string OperatorNotEqual = "!=";
13 | public const string OperatorGreaterThan = ">";
14 | public const string OperatorLessThan = "<";
15 | public const string OperatorGreaterThanOrEqual = ">=";
16 | public const string OperatorLessThanOrEqual = "<=";
17 |
18 | public const string MethodEquals = "OperatorEquals";
19 | public const string MethodNotEqual = "OperatorNotEqual";
20 | public const string MethodGreaterThan = "OperatorGreaterThan";
21 | public const string MethodLessThan = "OperatorLessThan";
22 | public const string MethodGreaterThanOrEqual = "OperatorGreaterThanOrEqual";
23 | public const string MethodLessThanOrEqual = "OperatorLessThanOrEqual";
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/FinallyClauseTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class FinallyClauseTranslation : CSharpSyntaxTranslation
12 | {
13 | public new FinallyClauseSyntax Syntax
14 | {
15 | get { return (FinallyClauseSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public FinallyClauseTranslation() { }
20 | public FinallyClauseTranslation(FinallyClauseSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Block = syntax.Block.Get(this);
23 | }
24 |
25 | public BlockTranslation Block { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $@"finally
30 | {Block.Translate()} ";
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VirtualTranslation/Delegates/ActionTypeGenericNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.VirtualTranslation
10 | {
11 | public class ActionTypeGenericNameTranslation : BaseFunctionGenericNameTranslation
12 | {
13 | public ActionTypeGenericNameTranslation(GenericNameTranslation genericNameTranslation) : base(genericNameTranslation)
14 | {
15 | Arguments = genericNameTranslation.TypeArgumentList.Arguments;
16 | this.Attach();
17 | }
18 |
19 | protected override string InnerTranslate()
20 | {
21 | List list = new List();
22 | string name = "";
23 | list = Arguments.GetEnumerable().Select(f => $"{name = GetFakeParamName(name)}:{f.Translate()}").ToList();
24 |
25 | return $"({string.Join(",", list)}) => void";
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VirtualTranslation/Delegates/BaseFunctionGenericNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.VirtualTranslation
10 | {
11 | public class BaseFunctionGenericNameTranslation : GenericNameTranslation
12 | {
13 | protected GenericNameTranslation genericNameTranslation;
14 |
15 | public BaseFunctionGenericNameTranslation(GenericNameTranslation genericNameTranslation)
16 | {
17 | this.genericNameTranslation = genericNameTranslation;
18 | this.Parent = genericNameTranslation.Parent;
19 | }
20 |
21 | public SeparatedSyntaxListTranslation Arguments { get; set; }
22 | public TypeTranslation ReturnType { get; set; }
23 |
24 | protected string GetFakeParamName(string previous)
25 | {
26 | return (previous ?? "") + "_";
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CaseSwitchLabelTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class CaseSwitchLabelTranslation : SwitchLabelTranslation
12 | {
13 | public new CaseSwitchLabelSyntax Syntax
14 | {
15 | get { return (CaseSwitchLabelSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public CaseSwitchLabelTranslation() { }
20 | public CaseSwitchLabelTranslation(CaseSwitchLabelSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Value = syntax.Value.Get(this);
23 | }
24 |
25 |
26 | public ExpressionTranslation Value { get; set; }
27 |
28 | protected override string InnerTranslate()
29 | {
30 | return $"case {Value.Translate()}:";
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/AwaitStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class AwaitExpressionTranslation : ExpressionTranslation
12 | {
13 | public new AwaitExpressionSyntax Syntax
14 | {
15 | get { return (AwaitExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public AwaitExpressionTranslation() { }
20 | public AwaitExpressionTranslation(AwaitExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Expression = syntax.Expression.Get(this);
23 | }
24 |
25 | public ExpressionTranslation Expression { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $"await {Expression.Translate()}";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CheckedExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class CheckedExpressionTranslation : ExpressionTranslation
12 | {
13 | public new CheckedExpressionSyntax Syntax
14 | {
15 | get { return (CheckedExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public CheckedExpressionTranslation() { }
20 | public CheckedExpressionTranslation(CheckedExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Expression = syntax.Expression.Get(this);
23 | }
24 |
25 | public ExpressionTranslation Expression { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $"({Expression.Translate()})";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/MemberBindingExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class MemberBindingExpressionTranslation : ExpressionTranslation
12 | {
13 | public new MemberBindingExpressionSyntax Syntax
14 | {
15 | get { return (MemberBindingExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public MemberBindingExpressionTranslation() { }
20 | public MemberBindingExpressionTranslation(MemberBindingExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Name = syntax.Name.Get(this);
23 |
24 | }
25 |
26 | public SimpleNameTranslation Name { get; set; }
27 |
28 | protected override string InnerTranslate()
29 | {
30 | return $".{Name.Translate()}";
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/LocalDeclarationStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class LocalDeclarationStatementTranslation : StatementTranslation
12 | {
13 | public new LocalDeclarationStatementSyntax Syntax
14 | {
15 | get { return (LocalDeclarationStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public VariableDeclarationTranslation Declaration { get; set; }
20 |
21 | public LocalDeclarationStatementTranslation(LocalDeclarationStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Declaration = syntax.Declaration.Get(this);
24 | }
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return string.Format("{0};", Declaration.Translate());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ParenthesizedExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ParenthesizedExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ParenthesizedExpressionSyntax Syntax
14 | {
15 | get { return (ParenthesizedExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ParenthesizedExpressionTranslation() { }
19 | public ParenthesizedExpressionTranslation(ParenthesizedExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Expression = syntax.Expression.Get(this);
22 | }
23 |
24 | public ExpressionTranslation Expression { get; set; }
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return $"({Expression.Translate()})";
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeArgumentListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeArgumentListTranslation : CSharpSyntaxTranslation
12 | {
13 | public new TypeArgumentListSyntax Syntax
14 | {
15 | get { return (TypeArgumentListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public TypeArgumentListTranslation() { }
20 | public TypeArgumentListTranslation(TypeArgumentListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Arguments = syntax.Arguments.Get(this);
23 | }
24 |
25 | public SeparatedSyntaxListTranslation Arguments { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $"<{Arguments.Translate()}> ";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ArgumentListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ArgumentListTranslation : CSharpSyntaxTranslation
12 | {
13 | public new ArgumentListSyntax Syntax
14 | {
15 | get { return (ArgumentListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public SeparatedSyntaxListTranslation Arguments { get; set; }
20 | public ArgumentListTranslation() { }
21 | public ArgumentListTranslation(ArgumentListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Arguments = syntax.Arguments.Get(this);
24 | }
25 |
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return string.Format("({0})", Arguments.Translate());
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/PrefixUnaryExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class PrefixUnaryExpressionTranslation : ExpressionTranslation
12 | {
13 | public new PrefixUnaryExpressionSyntax Syntax
14 | {
15 | get { return (PrefixUnaryExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public PrefixUnaryExpressionTranslation() { }
19 | public PrefixUnaryExpressionTranslation(PrefixUnaryExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Operand = syntax.Operand.Get(this);
22 | }
23 |
24 | public ExpressionTranslation Operand { get; set; }
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return $"{Syntax.OperatorToken.ToString()}{Operand.Translate()}";
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/PostfixUnaryExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class PostfixUnaryExpressionTranslation : ExpressionTranslation
12 | {
13 | public new PostfixUnaryExpressionSyntax Syntax
14 | {
15 | get { return (PostfixUnaryExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public PostfixUnaryExpressionTranslation() { }
19 | public PostfixUnaryExpressionTranslation(PostfixUnaryExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Operand = syntax.Operand.Get(this);
22 | }
23 |
24 | public ExpressionTranslation Operand { get; set; }
25 |
26 | protected override string InnerTranslate()
27 | {
28 | return $"{Operand.Translate()}{Syntax.OperatorToken.ToString()}";
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ArrayRankSpecifierTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ArrayRankSpecifierTranslation : CSharpSyntaxTranslation
12 | {
13 | public new ArrayRankSpecifierSyntax Syntax
14 | {
15 | get { return (ArrayRankSpecifierSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ArrayRankSpecifierTranslation() { }
19 | public ArrayRankSpecifierTranslation(ArrayRankSpecifierSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 |
22 | Sizes = syntax.Sizes.Get(this);
23 | }
24 |
25 | public SeparatedSyntaxListTranslation Sizes { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $"[{Sizes.Translate()}]";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BaseParameterListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class BaseParameterListTranslation : CSharpSyntaxTranslation
12 | {
13 | public new BaseParameterListSyntax Syntax
14 | {
15 | get { return (BaseParameterListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BaseParameterListTranslation() { }
20 | public BaseParameterListTranslation(BaseParameterListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Parameters = syntax.Parameters.Get(this);
23 | }
24 |
25 | public SeparatedSyntaxListTranslation Parameters { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return Syntax.ToString();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/TypeNameReplacement.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using Microsoft.CodeAnalysis;
8 | using Microsoft.CodeAnalysis.CSharp.Syntax;
9 | using TypescriptSyntaxPaste.VSIX;
10 |
11 | namespace TypescriptSyntaxPaste
12 | {
13 |
14 | public class TypeNameReplacement
15 | {
16 | public static CSharpSyntaxNode Replace(TypeNameReplacementData[] replacedTypeNameArray, CSharpSyntaxNode syntaxNode)
17 | {
18 | var typeNodes = syntaxNode.DescendantNodes()
19 | .OfType()
20 | .Where(f => replacedTypeNameArray.Any(r => r.OldTypeName == f.ToString()));
21 |
22 |
23 | return syntaxNode.ReplaceNodes(typeNodes, (n1, n2) => {
24 | var name = n1.ToString();
25 | var newName = replacedTypeNameArray.First(f => f.OldTypeName == name).NewTypeName;
26 | var newType = SyntaxFactory.ParseTypeName(newName);
27 |
28 | return newType;
29 | });
30 |
31 | }
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SyntaxListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using RoslynTypeScript.Contract;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class SyntaxListTranslation : SyntaxListBaseTranslation where T : SyntaxNode where ST :SyntaxTranslation
12 | {
13 | private SyntaxList syntaxList;
14 |
15 | public SyntaxListTranslation()
16 | {
17 | SyntaxCollection = new List();
18 | }
19 |
20 | public SyntaxListTranslation(SyntaxList syntaxList, SyntaxTranslation parent) :base(parent)
21 | {
22 | this.syntaxList = syntaxList;
23 | this.Parent = parent;
24 | SyntaxCollection = syntaxList.Select(f => f.Get(this)).ToList();
25 | }
26 |
27 |
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return string.Join("\r\n", SyntaxCollection.Select(f => f.Translate()));
32 | }
33 |
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
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 TypescriptSyntaxPaste.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeParameterTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeParameterTranslation : CSharpSyntaxTranslation
12 | {
13 | public new TypeParameterSyntax Syntax
14 | {
15 | get { return (TypeParameterSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public TypeParameterTranslation(TypeParameterSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
19 | {
20 | }
21 |
22 | public TypeTranslation TypeConstraint { get; set; }
23 |
24 | public bool IsExcludeConstraint { get; set; }
25 |
26 | protected override string InnerTranslate()
27 | {
28 | if(TypeConstraint!=null && !IsExcludeConstraint)
29 | {
30 | return $"{Syntax.Identifier} extends {TypeConstraint.Translate()}";
31 | }
32 |
33 | return Syntax.Identifier.ToString();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/NameOfExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | //using Microsoft.CodeAnalysis;
2 | //using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | //using System;
4 | //using System.Collections.Generic;
5 | //using System.Linq;
6 | //using System.Text;
7 | //using System.Threading.Tasks;
8 |
9 | //namespace RoslynTypeScript.Translation
10 | //{
11 | // public class NameOfExpressionTranslation : ExpressionTranslation
12 | // {
13 | // public new NameOfExpressionSyntax Syntax
14 | // {
15 | // get { return (NameOfExpressionSyntax)base.Syntax; }
16 | // set { base.Syntax = value; }
17 | // }
18 |
19 | // public NameOfExpressionTranslation() { }
20 | // public NameOfExpressionTranslation(NameOfExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | // {
22 | // Argument = syntax.Argument.Get(this);
23 | // }
24 |
25 | // public ExpressionTranslation Argument { get; set; }
26 |
27 | // protected override string InnerTranslate()
28 | // {
29 |
30 | // //return Syntax.ToString();
31 | // return $"'{Argument.Translate()}'";
32 | // }
33 | // }
34 | //}
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TokenTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.Translation
9 | {
10 | public class TokenTranslation : SyntaxTranslation
11 | {
12 | private SyntaxToken token;
13 | public TokenTranslation()
14 | { }
15 |
16 | public TokenTranslation(SyntaxToken token, SyntaxTranslation parent) : base(null, parent)
17 | {
18 | this.token = token;
19 |
20 | }
21 |
22 | protected override string InnerTranslate()
23 | {
24 | return Helper.NormalizeVariabeleName(token.ToString());
25 | }
26 |
27 | public virtual bool IsEmpty
28 | {
29 | get { return token.ToString() == string.Empty; }
30 | }
31 |
32 | public SyntaxToken Token
33 | {
34 | get
35 | {
36 | return token;
37 | }
38 | }
39 |
40 | public bool TokenEquals(TokenTranslation another)
41 | {
42 | return this.ToString() == another.ToString();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ClassTranslationTemplate.tt:
--------------------------------------------------------------------------------
1 | <#@ template hostspecific="false" language="C#" #>
2 | <#@ output extension=".cs" #>
3 | <#@ assembly name="System.Core" #>
4 | <#@ import namespace="System.Linq" #>
5 | <#@ import namespace="System.Text" #>
6 | <#@ import namespace="System.Collections.Generic" #>
7 | using Microsoft.CodeAnalysis;
8 | using Microsoft.CodeAnalysis.CSharp.Syntax;
9 | using System;
10 | using System.Collections.Generic;
11 | using System.Linq;
12 | using System.Text;
13 | using System.Threading.Tasks;
14 | <# string className = "AttributeList"; #>
15 |
16 | namespace RoslynTypeScript.Translation
17 | {
18 | public class <#=className#>Translation : SyntaxTranslation
19 | {
20 | public new <#=className#>Syntax Syntax
21 | {
22 | get { return (<#=className#>Syntax)base.Syntax; }
23 | set { base.Syntax = value; }
24 | }
25 |
26 | public <#=className#>Translation(){}
27 | public <#=className#>Translation(<#=className#>Syntax syntax, SyntaxTranslation parent): base(syntax, parent)
28 | {
29 |
30 | }
31 |
32 | protected override string InnerTranslate()
33 | {
34 | return Syntax.ToString();
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VSIX/PasteTextviewCreationListener.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using EnvDTE80;
3 | using Microsoft.VisualStudio.Editor;
4 | using Microsoft.VisualStudio.Shell;
5 | using Microsoft.VisualStudio.Text.Editor;
6 | using Microsoft.VisualStudio.TextManager.Interop;
7 | using Microsoft.VisualStudio.Utilities;
8 | using System.ComponentModel.Composition;
9 |
10 | namespace TypescriptSyntaxPaste
11 | {
12 | [PackageRegistration()]
13 | [Export(typeof(IVsTextViewCreationListener))]
14 | [ContentType("code")]
15 | [TextViewRole(PredefinedTextViewRoles.Editable)]
16 | class PasteTextViewCreationListener : IVsTextViewCreationListener
17 | {
18 | [Import]
19 | internal IVsEditorAdaptersFactoryService EditorAdaptersFactoryService { get; set; }
20 |
21 | public void VsTextViewCreated(IVsTextView textViewAdapter)
22 | {
23 | var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
24 | var dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
25 |
26 |
27 |
28 | textView.Properties.GetOrCreateSingletonProperty(() => new PasteCommandHandler(textViewAdapter, textView, dte));
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/AddIPrefixInterfaceDeclaration.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using Microsoft.CodeAnalysis.Editing;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace TypescriptSyntaxPaste
12 | {
13 | public class AddIPrefixInterfaceDeclaration
14 | {
15 | class AddIPrefixInterfaceDeclarationRewriter: CSharpSyntaxRewriter
16 | {
17 | public override SyntaxNode VisitInterfaceDeclaration(InterfaceDeclarationSyntax node)
18 | {
19 | var name = node.Identifier.ValueText;
20 | if (name.StartsWith("I"))
21 | {
22 | return base.VisitInterfaceDeclaration(node);
23 | }
24 |
25 | return node.ReplaceToken(node.Identifier, SyntaxFactory.ParseToken("I" + name));
26 | }
27 | }
28 |
29 | public static CSharpSyntaxNode AddIPrefix(CSharpSyntaxNode syntaxNode)
30 | {
31 | return (CSharpSyntaxNode)new AddIPrefixInterfaceDeclarationRewriter().Visit(syntaxNode);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ImplicitArrayCreationExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ImplicitArrayCreationExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ImplicitArrayCreationExpressionSyntax Syntax
14 | {
15 | get { return (ImplicitArrayCreationExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ImplicitArrayCreationExpressionTranslation() { }
20 | public ImplicitArrayCreationExpressionTranslation(ImplicitArrayCreationExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Initializer = syntax.Initializer.Get(this);
23 | }
24 |
25 | public InitializerExpressionTranslation Initializer { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | return $"new Array({Initializer.Expressions.Translate()})";
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CastExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using Microsoft.CodeAnalysis.CSharp;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class CastExpressionTranslation : ExpressionTranslation
13 | {
14 | public new CastExpressionSyntax Syntax
15 | {
16 | get { return (CastExpressionSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 | public CastExpressionTranslation() { }
20 | public CastExpressionTranslation(CastExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | Expression = syntax.Expression.Get(this);
24 | }
25 |
26 | public TypeTranslation Type { get; set; }
27 |
28 | public ExpressionTranslation Expression { get; set; }
29 |
30 | protected override string InnerTranslate()
31 | {
32 | return $"<{Type.Translate()}>{Expression.Translate()}";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/LockStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class LockStatementTranslation : StatementTranslation
12 | {
13 | public new LockStatementSyntax Syntax
14 | {
15 | get { return (LockStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public LockStatementTranslation() { }
20 | public LockStatementTranslation(LockStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Expression = syntax.Expression.Get(this);
23 | Statement = syntax.Statement.Get(this);
24 | }
25 |
26 | public ExpressionTranslation Expression { get; set; }
27 | public StatementTranslation Statement { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return $@"lock({Expression.Translate()})
32 | {Statement.Translate()}";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/DoStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class DoStatementTranslation : CSharpSyntaxTranslation
12 | {
13 | public new DoStatementSyntax Syntax
14 | {
15 | get { return (DoStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public DoStatementTranslation() { }
20 | public DoStatementTranslation(DoStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Condition = syntax.Condition.Get(this);
23 | Statement = syntax.Statement.Get(this);
24 | }
25 |
26 | public ExpressionTranslation Condition { get; set; }
27 | public StatementTranslation Statement { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return $@"do
32 | {Statement.Translate()}
33 | while({Condition.Translate()});";
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/WhileStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class WhileStatementTranslation : CSharpSyntaxTranslation
12 | {
13 | public new WhileStatementSyntax Syntax
14 | {
15 | get { return (WhileStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public WhileStatementTranslation() { }
20 | public WhileStatementTranslation(WhileStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Condition = syntax.Condition.Get(this);
23 | Statement = syntax.Statement.Get(this);
24 | }
25 |
26 | public ExpressionTranslation Condition { get; set; }
27 | public StatementTranslation Statement { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return $"while ({Condition.Translate()})"
32 | + $"\n {Statement.Translate()}";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/EqualsValueClauseTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class EqualsValueClauseTranslation : CSharpSyntaxTranslation
13 | {
14 | public new EqualsValueClauseSyntax Syntax
15 | {
16 | get { return (EqualsValueClauseSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 | public ExpressionTranslation Value { get; set; }
20 | public EqualsValueClauseTranslation(EqualsValueClauseSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Value = syntax.Value.Get(this);
23 | }
24 |
25 | public override void ApplyPatch()
26 | {
27 | base.ApplyPatch();
28 | Helper.ApplyFunctionBindToCorrectContext(this.Value);
29 | }
30 |
31 | protected override string InnerTranslate()
32 | {
33 | var expr = Value.Translate();
34 |
35 | return string.Format("= {0}", expr);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BaseTypeDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using RoslynTypeScript.Patch;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public abstract class BaseTypeDeclarationTranslation : MemberDeclarationTranslation
13 | {
14 | public BaseTypeDeclarationTranslation() { }
15 | public BaseTypeDeclarationTranslation(BaseTypeDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
16 | {
17 | Modifiers = syntax.Modifiers.Get(this);
18 | AttributeList = syntax.AttributeLists.Get(this);
19 | }
20 |
21 | public SyntaxTokenListTranslation Modifiers { get; set; }
22 | public SyntaxListTranslation AttributeList { get; set; }
23 |
24 | public override void ApplyPatch()
25 | {
26 | InnerTypeDeclarationPatch innerTypeDeclarationPatch = new InnerTypeDeclarationPatch();
27 | innerTypeDeclarationPatch.Apply(this);
28 | base.ApplyPatch();
29 |
30 | }
31 |
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/EnumDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class EnumDeclarationTranslation : BaseTypeDeclarationTranslation
12 | {
13 | public new EnumDeclarationSyntax Syntax
14 | {
15 | get { return (EnumDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public EnumDeclarationTranslation() { }
19 | public EnumDeclarationTranslation(EnumDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Members = syntax.Members.Get(this);
22 | Members.IsNewLine = true;
23 | }
24 |
25 | public SeparatedSyntaxListTranslation Members { get; set; }
26 |
27 |
28 | protected override string InnerTranslate()
29 | {
30 | return $@"export enum {Syntax.Identifier} {{
31 | {Members.Translate()}
32 | }}";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SimpleLambdaExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class SimpleLambdaExpressionTranslation : ExpressionTranslation
12 | {
13 | public new SimpleLambdaExpressionSyntax Syntax
14 | {
15 | get { return (SimpleLambdaExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public SimpleLambdaExpressionTranslation() { }
20 | public SimpleLambdaExpressionTranslation(SimpleLambdaExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Body = syntax.Body.Get(this);
23 | Parameter = syntax.Parameter.Get(this);
24 | }
25 |
26 | public CSharpSyntaxTranslation Body { get; set; }
27 | public ParameterTranslation Parameter { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | //return Syntax.ToString();
32 | return $"{Parameter.Translate()} => {Body.Translate()}";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/VirtualTranslation/Delegates/FunctionTypeGenericNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.VirtualTranslation
10 | {
11 | public class FunctionTypeGenericNameTranslation : BaseFunctionGenericNameTranslation
12 | {
13 | public FunctionTypeGenericNameTranslation(GenericNameTranslation genericNameTranslation) :base(genericNameTranslation)
14 | {
15 | ReturnType = genericNameTranslation.TypeArgumentList.Arguments.GetEnumerable().Last();
16 | Arguments = new SeparatedSyntaxListTranslation();
17 | Arguments.Add(genericNameTranslation.TypeArgumentList.Arguments.GetEnumerable().Where(f => f != ReturnType));
18 | this.Attach();
19 | }
20 |
21 | protected override string InnerTranslate()
22 | {
23 | List list = new List();
24 | string name = "";
25 | list = Arguments.GetEnumerable().Select(f => $"{name = GetFakeParamName(name)}:{f.Translate()}").ToList();
26 |
27 | return $"({string.Join(",", list)}) => {ReturnType.Translate()}";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ParenthesizedLambdaExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ParenthesizedLambdaExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ParenthesizedLambdaExpressionSyntax Syntax
14 | {
15 | get { return (ParenthesizedLambdaExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ParenthesizedLambdaExpressionTranslation() { }
20 | public ParenthesizedLambdaExpressionTranslation(ParenthesizedLambdaExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Body = syntax.Body.Get(this);
23 | ParameterList = syntax.ParameterList.Get(this);
24 | }
25 |
26 | public CSharpSyntaxTranslation Body { get; set; }
27 | public ParameterListTranslation ParameterList { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return $"{ParameterList.Translate()} => {Body.Translate()}";
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ClassStructDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.CodeAnalysis;
7 | using Microsoft.CodeAnalysis.CSharp.Syntax;
8 | using RoslynTypeScript.Patch;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public abstract class ClassStructDeclarationTranslation :TypeDeclarationTranslation
13 | {
14 | public ClassStructDeclarationTranslation(TypeDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
15 | {
16 | if (syntax.BaseList != null)
17 | {
18 | BaseList = syntax.BaseList.Get(this);
19 | }
20 | }
21 |
22 | public override void ApplyPatch()
23 | {
24 | base.ApplyPatch();
25 | // ConstructorPatch constructorPatch = new ConstructorPatch();
26 | // constructorPatch.Apply(this);
27 | }
28 |
29 | public BaseListTranslation BaseList { get; set; }
30 |
31 | public bool HasExplicitBase()
32 | {
33 | if (Syntax.BaseList == null)
34 | {
35 | return false;
36 | }
37 |
38 | return BaseList.GetBaseClass() != null;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ConditionalAccessExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ConditionalAccessExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ConditionalAccessExpressionSyntax Syntax
14 | {
15 | get { return (ConditionalAccessExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ConditionalAccessExpressionTranslation() { }
20 | public ConditionalAccessExpressionTranslation(ConditionalAccessExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Expression = syntax.Expression.Get(this);
23 | WhenNotNull = syntax.WhenNotNull.Get(this);
24 |
25 | }
26 |
27 | public ExpressionTranslation Expression { get; set; }
28 | public ExpressionTranslation WhenNotNull { get; set; }
29 |
30 | protected override string InnerTranslate()
31 | {
32 | return $"{Expression.Translate()}?{WhenNotNull.Translate()}";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/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("VSIXProject5")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("VSIXProject5")]
13 | [assembly: AssemblyCopyright("")]
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 | // Version information for an assembly consists of the following four values:
23 | //
24 | // Major Version
25 | // Minor Version
26 | // Build Number
27 | // Revision
28 | //
29 | // You can specify all the values or you can default the Build and Revision Numbers
30 | // by using the '*' as shown below:
31 | // [assembly: AssemblyVersion("1.0.*")]
32 | [assembly: AssemblyVersion("1.0.0.0")]
33 | [assembly: AssemblyFileVersion("1.0.0.0")]
34 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ConstructorInitializerTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ConstructorInitializerTranslation : CSharpSyntaxTranslation
12 | {
13 | public new ConstructorInitializerSyntax Syntax
14 | {
15 | get { return (ConstructorInitializerSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ConstructorInitializerTranslation() { }
19 | public ConstructorInitializerTranslation(ConstructorInitializerSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 |
22 | ThisOrBaseKeyword = syntax.ThisOrBaseKeyword.Get(this);
23 | ArgumentList = syntax.ArgumentList.Get(this);
24 | }
25 |
26 | public TokenTranslation ThisOrBaseKeyword { get; set; }
27 | public ArgumentListTranslation ArgumentList { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | string thisOrBase = Syntax.ThisOrBaseKeyword.ToString() == "this" ? "this" : "super";
32 | return $"{thisOrBase}{ArgumentList.Translate()};";
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/FieldDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class FieldDeclarationTranslation : MemberDeclarationTranslation
12 | {
13 | public new FieldDeclarationSyntax Syntax
14 | {
15 | get { return (FieldDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public VariableDeclarationTranslation Declaration { get; set; }
19 | public SyntaxTokenListTranslation Modifiers { get; set; }
20 |
21 | public FieldDeclarationTranslation() { }
22 | public FieldDeclarationTranslation(FieldDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Declaration = syntax.Declaration.Get(this);
25 | Declaration.ExcludeVar = true;
26 | Modifiers = syntax.Modifiers.Get(this);
27 | Modifiers.ConstantToStatic = true;
28 | }
29 |
30 | protected override string InnerTranslate()
31 | {
32 | return string.Format("{0} {1};", Modifiers.Translate(), Declaration.Translate());
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BlockTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BlockTranslation : StatementTranslation
12 | {
13 | public new BlockSyntax Syntax
14 | {
15 | get { return (BlockSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public SyntaxListTranslation Statements { get; set; }
19 |
20 | public BlockTranslation()
21 | {
22 | Statements = new SyntaxListTranslation();
23 | }
24 |
25 | public BlockTranslation(BlockSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
26 | {
27 | Statements = syntax.Statements.Get(this);
28 | }
29 |
30 | public bool IsIgnoreBracket { get; set; }
31 |
32 | protected override string InnerTranslate()
33 | {
34 | if(IsIgnoreBracket)
35 | {
36 | return Statements.Translate();
37 | }
38 |
39 | return string.Format(@"{{
40 | {0}
41 | }}", Statements.Translate());
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeParameterConstraintClauseTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeParameterConstraintClauseTranslation : SyntaxTranslation
12 | {
13 | public new TypeParameterConstraintClauseSyntax Syntax
14 | {
15 | get { return (TypeParameterConstraintClauseSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public TypeParameterConstraintClauseTranslation() { }
20 | public TypeParameterConstraintClauseTranslation(TypeParameterConstraintClauseSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Constraints = syntax.Constraints.Get(this);
23 | Name = syntax.Name.Get(this);
24 | }
25 |
26 | public SeparatedSyntaxListTranslation Constraints { get; set; }
27 | public IdentifierNameTranslation Name { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return Syntax.ToString();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CatchClauseTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class CatchClauseTranslation : CSharpSyntaxTranslation
12 | {
13 | public new CatchClauseSyntax Syntax
14 | {
15 | get { return (CatchClauseSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public CatchClauseTranslation() { }
20 | public CatchClauseTranslation(CatchClauseSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Block = syntax.Block.Get(this);
23 | Declaration = syntax.Declaration.Get(this);
24 | }
25 |
26 | public BlockTranslation Block { get; set; }
27 | public CatchDeclarationTranslation Declaration { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | string errName = Declaration?.Syntax.Identifier.ToString();
32 | if(string.IsNullOrEmpty(errName))
33 | {
34 | errName = "err";
35 | }
36 |
37 | return $@"catch({errName})
38 | {Block.Translate()}";
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/InterfaceDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class InterfaceDeclarationTranslation : TypeDeclarationTranslation
12 | {
13 | public new InterfaceDeclarationSyntax Syntax
14 | {
15 | get { return (InterfaceDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public InterfaceDeclarationTranslation(InterfaceDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 |
22 | if (syntax.BaseList != null)
23 | {
24 | BaseList = syntax.BaseList.Get(this);
25 | BaseList.IsForInterface = true;
26 | }
27 | }
28 |
29 | public BaseListTranslation BaseList { get; set; }
30 |
31 | protected override string InnerTranslate()
32 | {
33 | string baseTranslation = BaseList?.Translate();
34 | return $@"{GetAttributeList()}export interface {Syntax.Identifier} {TypeParameterList?.Translate()} {baseTranslation}
35 | {{
36 | {Members.Translate()}
37 | }}";
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BasePropertyDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class BasePropertyDeclarationTranslation : MemberDeclarationTranslation
12 | {
13 | public new BasePropertyDeclarationSyntax Syntax
14 | {
15 | get { return (BasePropertyDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public BasePropertyDeclarationTranslation() { }
20 | public BasePropertyDeclarationTranslation(BasePropertyDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | AccessorList = syntax.AccessorList.Get(this);
24 | Modifiers = syntax.Modifiers.Get(this);
25 |
26 | AccessorList.SetModifier(Modifiers);
27 | }
28 |
29 | public AccessorListTranslation AccessorList { get; set; }
30 | public SyntaxTokenListTranslation Modifiers { get; set; }
31 |
32 | public TypeTranslation Type { get; set; }
33 | protected override string InnerTranslate()
34 | {
35 | return Syntax.ToString();
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ConversionOperatorDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class ConversionOperatorDeclarationTranslation : BaseMethodDeclarationTranslation
13 | {
14 | public new ConversionOperatorDeclarationSyntax Syntax
15 | {
16 | get { return (ConversionOperatorDeclarationSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public ConversionOperatorDeclarationTranslation() { }
21 | public ConversionOperatorDeclarationTranslation(ConversionOperatorDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Type = syntax.Type.Get(this);
24 | }
25 |
26 | public TypeTranslation Type { get; set; }
27 |
28 | protected override string InnerTranslate()
29 | {
30 | var semanticModel = GetSemanticModel();
31 | var symbol = semanticModel.GetDeclaredSymbol(this.Syntax);
32 |
33 | return $@"{Modifiers.Translate()} conversionMethod {ParameterList.Translate()} : {Type.Translate()}
34 | {Body.Translate()}";
35 |
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ConditionalExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ConditionalExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ConditionalExpressionSyntax Syntax
14 | {
15 | get { return (ConditionalExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ConditionalExpressionTranslation() { }
20 | public ConditionalExpressionTranslation(ConditionalExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Condition = syntax.Condition.Get(this);
23 | WhenFalse = syntax.WhenFalse.Get(this);
24 | WhenTrue = syntax.WhenTrue.Get(this);
25 | }
26 |
27 | public ExpressionTranslation Condition { get; set; }
28 | public ExpressionTranslation WhenFalse { get; set; }
29 | public ExpressionTranslation WhenTrue { get; set; }
30 |
31 | protected override string InnerTranslate()
32 | {
33 | return $"{Condition.Translate()} ? {WhenTrue.Translate()} : {WhenFalse.Translate()}";
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/OptionalInterfaceProperties.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace TypescriptSyntaxPaste
11 | {
12 | public class OptionalInterfaceProperties
13 | {
14 | public static CSharpSyntaxNode AddOptional(CSharpSyntaxNode syntaxNode)
15 | {
16 | var interfaces = syntaxNode.DescendantNodesAndSelf().Where(f => f is InterfaceDeclarationSyntax);
17 |
18 | var properties = interfaces.SelectMany(f => f.DescendantNodes().Where(c => c is PropertyDeclarationSyntax));
19 | var methods = interfaces.SelectMany(f => f.DescendantNodes().Where(c => c is MethodDeclarationSyntax));
20 |
21 | return syntaxNode.ReplaceNodes(properties.Concat(methods), (node, node2) =>
22 | {
23 | var property = node as PropertyDeclarationSyntax;
24 | var method = node as MethodDeclarationSyntax;
25 | if (property != null)
26 | {
27 | return property.WithIdentifier(SyntaxFactory.Identifier(property.Identifier.ValueText + "?"));
28 | }
29 |
30 | return method.WithIdentifier(SyntaxFactory.Identifier(method.Identifier.ValueText + "?"));
31 | });
32 |
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Patch/ArrayInitReturnForYieldPatch.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using RoslynTypeScript.Constants;
7 | using RoslynTypeScript.Translation;
8 |
9 | namespace RoslynTypeScript.Patch
10 | {
11 | ///
12 | /// try to replace yield statement with array.push, then return array at the end of method.
13 | ///
14 | public class ArrayInitReturnForYieldPatch : Patch
15 | {
16 | public void Apply(MethodDeclarationTranslation method)
17 | {
18 | if (!method.IsYieldReturn)
19 | {
20 | return;
21 | }
22 |
23 | var arrayCreation = new ArrayCreationExpressionTranslation();
24 | string typeParemter = string.Empty;
25 | var genericType = method.ReturnType as GenericNameTranslation;
26 | if (genericType != null)
27 | {
28 | typeParemter = genericType.TypeArgumentList.Translate();
29 | }
30 | arrayCreation.SyntaxString = $"var {TC.YieldResultName} = new Array{typeParemter}();";
31 |
32 | var returnStatement = new ReturnStatementTranslation();
33 | returnStatement.SyntaxString = $"return {TC.YieldResultName};";
34 |
35 | method.Body.Statements.Insert(0, arrayCreation);
36 | method.Body.Statements.Add(returnStatement);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ReturnStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class ReturnStatementTranslation : StatementTranslation
13 | {
14 | public new ReturnStatementSyntax Syntax
15 | {
16 | get { return (ReturnStatementSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 | public ExpressionTranslation Expression { get; set; }
20 | public ReturnStatementTranslation() { }
21 | public ReturnStatementTranslation(ReturnStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Expression = syntax.Expression.Get(this);
24 | }
25 |
26 | public override void ApplyPatch()
27 | {
28 | base.ApplyPatch();
29 | Helper.ApplyFunctionBindToCorrectContext(this.Expression);
30 | }
31 |
32 | protected override string InnerTranslate()
33 | {
34 | if (Expression == null)
35 | {
36 | return "return";
37 | }
38 |
39 | var expr = Expression.Translate();
40 |
41 | return $"return {expr};";
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ElementAccessExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using RoslynTypeScript.Constants;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class ElementAccessExpressionTranslation : ExpressionTranslation
13 | {
14 | public new ElementAccessExpressionSyntax Syntax
15 | {
16 | get { return (ElementAccessExpressionSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 | public ElementAccessExpressionTranslation() { }
20 | public ElementAccessExpressionTranslation(ElementAccessExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | ArgumentList = syntax.ArgumentList.Get(this);
23 | Expression = syntax.Expression.Get(this);
24 | }
25 |
26 | public BracketedArgumentListTranslation ArgumentList { get; set; }
27 | public ExpressionTranslation Expression { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | return NormalTranslate();
32 | }
33 |
34 | private string NormalTranslate()
35 | {
36 | return $"{Expression.Translate()}{ArgumentList.Translate()}";
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Tests/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/AccessorListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class AccessorListTranslation : CSharpSyntaxTranslation
12 | {
13 |
14 | public SyntaxListTranslation Accessors { get; set; }
15 |
16 | public AccessorListTranslation(AccessorListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
17 | {
18 | Accessors = syntax.Accessors.Get(this);
19 | }
20 |
21 | public void SetModifier(SyntaxTokenListTranslation modifiers)
22 | {
23 | foreach (var item in Accessors.GetEnumerable())
24 | {
25 | item.ParentModifiers = modifiers.TokenListSyntax.Get(item);
26 | }
27 | }
28 |
29 | public new AccessorListSyntax Syntax
30 | {
31 | get { return (AccessorListSyntax)base.Syntax; }
32 | set { base.Syntax = value; }
33 | }
34 |
35 | protected override string InnerTranslate()
36 | {
37 | return Accessors.Translate();
38 | }
39 |
40 | public bool IsShorten()
41 | {
42 | return Accessors.GetEnumerable().First().IsShorten();
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/LabeledStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using RoslynTypeScript.Patch;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class LabeledStatementTranslation : SyntaxTranslation
13 | {
14 | public new LabeledStatementSyntax Syntax
15 | {
16 | get { return (LabeledStatementSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public LabeledStatementTranslation() { }
21 | public LabeledStatementTranslation(LabeledStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Statement = syntax.Statement.Get(this);
24 | }
25 |
26 | public StatementTranslation Statement { get; set; }
27 |
28 | public override void ApplyPatch()
29 | {
30 | base.ApplyPatch();
31 |
32 | }
33 |
34 | public bool TakeCare { get; set; }
35 |
36 | public bool IgnoreLabel { get; set; }
37 |
38 | protected override string InnerTranslate()
39 | {
40 |
41 | //string add = TakeCare ? "(^_^)" :"";
42 | string label = IgnoreLabel ? string.Empty : Syntax.Identifier.ToString() + ":";
43 | return $@"{label}
44 | {Statement.Translate()}";
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SimpleNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class SimpleNameTranslation : NameTranslation
12 | {
13 | public SimpleNameTranslation() { }
14 | public SimpleNameTranslation(SimpleNameSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
15 | {
16 | }
17 |
18 |
19 | public bool DetectApplyThis { get; set; } = true;
20 |
21 |
22 | protected string HandleApplyStaticOrThis(string syntaxStr)
23 | {
24 | SemanticModel semanticModel = GetSemanticModel();
25 | if(semanticModel == null)
26 | {
27 | return null;
28 | }
29 |
30 | SymbolInfo symbolInfo = semanticModel.GetSymbolInfo(Syntax);
31 |
32 | if (symbolInfo.Symbol != null && (
33 | symbolInfo.Symbol.Kind == SymbolKind.Field
34 | || symbolInfo.Symbol.Kind == SymbolKind.Property
35 | || symbolInfo.Symbol.Kind == SymbolKind.Method))
36 | {
37 | var result = Helper.ApplyThis(semanticModel, this, syntaxStr);
38 | if (result != null)
39 | {
40 | return result;
41 | }
42 | }
43 |
44 | return null;
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ClassDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using RoslynTypeScript.Patch;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using RoslynTypeScript.Contract;
10 |
11 | namespace RoslynTypeScript.Translation
12 | {
13 | public class ClassDeclarationTranslation : ClassStructDeclarationTranslation, IBaseExtended
14 | {
15 | public new ClassDeclarationSyntax Syntax
16 | {
17 | get { return (ClassDeclarationSyntax)base.Syntax; }
18 | set { base.Syntax = value; }
19 | }
20 |
21 | public ClassDeclarationTranslation(ClassDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | var constructor = Members.GetEnumerable().FirstOrDefault();
24 | if (constructor == null)
25 | {
26 | return;
27 | }
28 | }
29 |
30 | public override void ApplyPatch()
31 | {
32 | base.ApplyPatch();
33 | }
34 |
35 | protected override string InnerTranslate()
36 | {
37 |
38 | string baseTranslation = BaseList?.Translate();
39 |
40 | return $@"{GetAttributeList()}export class {Syntax.Identifier}{TypeParameterList?.Translate()} {baseTranslation}
41 | {{
42 | {Members.Translate()}
43 | }}";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ThrowStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ThrowStatementTranslation : StatementTranslation
12 | {
13 | public new ThrowStatementSyntax Syntax
14 | {
15 | get { return (ThrowStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ThrowStatementTranslation() { }
20 | public ThrowStatementTranslation(ThrowStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Expression = syntax.Expression.Get(this);
23 | }
24 |
25 | public ExpressionTranslation Expression { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 |
30 | var err = "err";
31 | // try to find exception variable from catch clause
32 | if (Expression == null)
33 | {
34 | var tokenText = this.Syntax.Ancestors().OfType().FirstOrDefault()?.Declaration?.Identifier.ValueText;
35 |
36 | err = tokenText ?? err;
37 |
38 | }
39 | else
40 | {
41 | err = Expression.Translate();
42 | }
43 |
44 | return $"throw {err};";
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ArrayTypeTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ArrayTypeTranslation : TypeTranslation
12 | {
13 | public new ArrayTypeSyntax Syntax
14 | {
15 | get { return (ArrayTypeSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ArrayTypeTranslation() { }
19 | public ArrayTypeTranslation(ArrayTypeSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 |
22 | RankSpecifiers = syntax.RankSpecifiers.Get(this);
23 | ElementType = syntax.ElementType.Get(this);
24 | }
25 |
26 | public SyntaxListTranslation RankSpecifiers { get; set; }
27 | public TypeTranslation ElementType { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | string elementTypeStr = ElementType.Translate();
32 |
33 | // in javascript for byte array, we will use
34 | if(elementTypeStr == "byte")
35 | {
36 | return "Int8Array";
37 | }
38 |
39 | return $"{elementTypeStr}{RankSpecifiers.Translate()}";
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.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("TypescriptSyntaxPaste.Tests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("TypescriptSyntaxPaste.Tests")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
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("2d69301b-a90b-4601-8330-a9a908332744")]
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 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SwitchSectionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class SwitchSectionTranslation : SyntaxTranslation
13 | {
14 | public new SwitchSectionSyntax Syntax
15 | {
16 | get { return (SwitchSectionSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public SwitchSectionTranslation() { }
21 | public SwitchSectionTranslation(SwitchSectionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Labels = syntax.Labels.Get(this);
24 | Statements = syntax.Statements.Get(this);
25 | }
26 | public SyntaxListTranslation Labels { get; set; }
27 | public SyntaxListTranslation Statements { get; set; }
28 |
29 | public bool IsDefaultCase
30 | {
31 | get { return Labels.GetEnumerable().Any(f => f.Syntax.IsKind(SyntaxKind.DefaultSwitchLabel)); }
32 | }
33 |
34 | protected override string InnerTranslate()
35 | {
36 | return $@"{Labels.Translate()}
37 | {Statements.Translate()}";
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Console/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("TypescriptSyntaxPaste.Console")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("TypescriptSyntaxPaste.Console")]
13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
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("0155f584-bd9c-4d25-b3f6-d99d8772f030")]
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 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/NamespaceDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class NamespaceDeclarationTranslation : CSharpSyntaxTranslation
12 | {
13 | public new MemberDeclarationSyntax Syntax
14 | {
15 | get { return (MemberDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public SyntaxListTranslation Members { get; set; }
20 | public NameTranslation Name { get; set; }
21 |
22 | public bool IsExport { get; set; }
23 |
24 | public NamespaceDeclarationTranslation()
25 | {
26 |
27 | }
28 |
29 | public NamespaceDeclarationTranslation(NamespaceDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
30 | {
31 | Members = syntax.Members.Get(this);
32 | Name = syntax.Name.Get(this);
33 | }
34 |
35 | protected override string InnerTranslate()
36 | {
37 | string exportStr = IsExport ? "export" : "";
38 |
39 | return $@"{exportStr} module {Name.Translate()}
40 | {{
41 | {Members.Translate()}
42 | }}";
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ParameterListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ParameterListTranslation : CSharpSyntaxTranslation
12 | {
13 | public new ParameterListSyntax Syntax
14 | {
15 | get { return (ParameterListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public SeparatedSyntaxListTranslation Parameters { get; set; }
20 |
21 | public ParameterListTranslation()
22 | {
23 | }
24 |
25 | public ParameterListTranslation(ParameterListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
26 | {
27 | Parameters = syntax.Parameters.Get(this);
28 | }
29 |
30 | private bool excludeDefaultValue;
31 |
32 | public bool ExcludeDefaultValue
33 | {
34 | get { return excludeDefaultValue; }
35 | set {
36 | excludeDefaultValue = value;
37 | foreach (var item in Parameters.GetEnumerable())
38 | {
39 | item.ExcludeDefaultValue = value;
40 |
41 | }
42 | }
43 | }
44 |
45 | protected override string InnerTranslate()
46 | {
47 | return $"({Parameters.Translate()})";
48 | }
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/IfStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class IfStatementTranslation : StatementTranslation
12 | {
13 | public new IfStatementSyntax Syntax
14 | {
15 | get { return (IfStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public IfStatementTranslation() { }
20 |
21 |
22 | public IfStatementTranslation(IfStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Condition = syntax.Condition.Get(this);
25 | Statement = syntax.Statement.Get(this);
26 | Else = syntax.Else.Get(this);
27 | }
28 |
29 | public ExpressionTranslation Condition { get; set; }
30 |
31 | public StatementTranslation Statement { get; }
32 |
33 | public ElseClauseTranslation Else { get; set; }
34 |
35 | public string FullConditionStr { get; set; }
36 |
37 | protected override string InnerTranslate()
38 | {
39 | string result = $"if({Condition.Translate()})"
40 | + $"\n {Statement.Translate()}";
41 | if (Else != null)
42 | {
43 | result += $"\n {Else.Translate()}";
44 | }
45 |
46 | return result;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeOfExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeOfExpressionTranslation : ExpressionTranslation
12 | {
13 | public new TypeOfExpressionSyntax Syntax
14 | {
15 | get { return (TypeOfExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public TypeOfExpressionTranslation() { }
20 | public TypeOfExpressionTranslation(TypeOfExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | }
24 |
25 | public TypeTranslation Type { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | var str = Type.Translate();
30 | switch (str)
31 | {
32 | case "number":
33 | str = "Number";
34 | break;
35 | case "string":
36 | str = "String";
37 | break;
38 | case "boolean":
39 | str = "Boolean";
40 | break;
41 |
42 | }
43 | // for typeof, we translate to Object type of primitive type, for example number -> Number
44 |
45 | return $"/*typeof*/{Type.GetTypeIgnoreGeneric()} ";
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SwitchStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using RoslynTypeScript.Patch;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class SwitchStatementTranslation : StatementTranslation
13 | {
14 | public new SwitchStatementSyntax Syntax
15 | {
16 | get { return (SwitchStatementSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public SwitchStatementTranslation() { }
21 | public SwitchStatementTranslation(SwitchStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Expression = syntax.Expression.Get(this);
24 | Sections = syntax.Sections.Get(this);
25 | }
26 |
27 | public ExpressionTranslation Expression { get; set; }
28 | public SyntaxListTranslation Sections { get; set; }
29 |
30 | public bool GotoExists { get; set; }
31 | public bool GotoDefaultExists { get; set; }
32 |
33 | public override void ApplyPatch()
34 | {
35 | base.ApplyPatch();
36 | }
37 |
38 | protected override string InnerTranslate()
39 | {
40 | return $@"switch({Expression.Translate()})
41 | {{
42 | {Sections.Translate()}
43 | }}";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ForEachStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ForEachStatementTranslation : StatementTranslation
12 | {
13 | public new ForEachStatementSyntax Syntax
14 | {
15 | get { return (ForEachStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ForEachStatementTranslation() { }
20 | public ForEachStatementTranslation(ForEachStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Expression = syntax.Expression.Get(this);
23 | Statement = syntax.Statement.Get(this);
24 | Type = syntax.Type.Get(this);
25 | }
26 |
27 | public ExpressionTranslation Expression { get; set; }
28 | //public SyntaxToken Identifier { get; }
29 | public StatementTranslation Statement { get; set; }
30 | public TypeTranslation Type { get; set; }
31 |
32 | protected override string InnerTranslate()
33 | {
34 |
35 | var expression = Statement is BlockTranslation ? Statement.Translate() : "{" + Statement.Translate() + "}";
36 | var statement = @"{0}.forEach(function({1}){2});";
37 |
38 | return string.Format(statement, Expression.Translate(), Syntax.Identifier, expression);
39 |
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeParameterListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class TypeParameterListTranslation : SyntaxTranslation
12 | {
13 | public new TypeParameterListSyntax Syntax
14 | {
15 | get { return (TypeParameterListSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public SeparatedSyntaxListTranslation Parameters { get; set; }
19 |
20 | public TypeParameterListTranslation() { }
21 |
22 | public TypeParameterListTranslation(TypeParameterListSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Parameters = syntax.Parameters.Get(this);
25 | }
26 |
27 | private bool isExcludeConstraint;
28 | public bool IsExcludeConstraint
29 | {
30 | get { return this.isExcludeConstraint; }
31 | set
32 | {
33 | this.isExcludeConstraint = value;
34 | foreach (var item in Parameters.GetEnumerable())
35 | {
36 | item.IsExcludeConstraint = value;
37 | }
38 | }
39 | }
40 |
41 | protected override string InnerTranslate()
42 | {
43 | return string.Format("<{0}>", Parameters.Translate());
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ArgumentTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class ArgumentTranslation : SyntaxTranslation
13 | {
14 | public new ArgumentSyntax Syntax
15 | {
16 | get { return (ArgumentSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public ArgumentTranslation() { }
21 |
22 | public ArgumentTranslation(ArgumentSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Expression = syntax.Expression.Get(this);
25 | }
26 |
27 | public ExpressionTranslation Expression { get; set; }
28 |
29 |
30 | public bool IsExistingRefOrOutKeyword
31 | {
32 | get { return !Syntax.RefOrOutKeyword.Span.IsEmpty; }
33 | }
34 |
35 | public override void ApplyPatch()
36 | {
37 | base.ApplyPatch();
38 | Helper.ApplyFunctionBindToCorrectContext(this.Expression);
39 | }
40 |
41 | protected override string InnerTranslate()
42 | {
43 |
44 | string nameColon = string.Empty;
45 | if (Syntax.NameColon != null)
46 | {
47 | nameColon = $"/*{Syntax.NameColon.ToString()}*/";
48 | }
49 | return $"{nameColon}{Expression.Translate()}";
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ArrayCreationExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ArrayCreationExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ArrayCreationExpressionSyntax Syntax
14 | {
15 | get { return (ArrayCreationExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ArrayCreationExpressionTranslation() { }
20 | public ArrayCreationExpressionTranslation(ArrayCreationExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | Initializer = syntax.Initializer.Get(this);
24 | }
25 |
26 | public ArrayTypeTranslation Type { get; set; }
27 | public InitializerExpressionTranslation Initializer { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | // now only support 1-dimension
32 |
33 | if (Initializer == null)
34 | {
35 | var semantic = GetSemanticModel();
36 | var typeInfo = semantic.GetTypeInfo(Type.ElementType.Syntax);
37 |
38 | string size = Type.RankSpecifiers.GetEnumerable().First().Sizes.Translate();
39 | return $"new Array({size})";
40 | }
41 | else
42 | {
43 | return $"{Initializer.Expressions.Translate()}";
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Patch/GenericConstrantsPatch.cs:
--------------------------------------------------------------------------------
1 | using RoslynTypeScript.Contract;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Patch
10 | {
11 | public class GenericConstrantsPatch : Patch
12 | {
13 | ///
14 | /// Buid generic constrant
15 | ///
16 | ///
17 | public void Apply(ITypeParameterConstraint typeDeclarationTranslation)
18 | {
19 |
20 | if(typeDeclarationTranslation.TypeParameterList == null)
21 | {
22 | return;
23 | }
24 |
25 | var parameters = typeDeclarationTranslation.TypeParameterList.Parameters.GetEnumerable();
26 | foreach (TypeParameterTranslation item in parameters)
27 | {
28 | var foundClause = typeDeclarationTranslation.ConstraintClauses
29 | .GetEnumerable().FirstOrDefault(f => f.Name.Translate() == item.Syntax.Identifier.ToString());
30 | if (foundClause == null)
31 | {
32 | continue;
33 | }
34 |
35 | var constraints = foundClause.Constraints.GetEnumerable().OfType().ToArray();
36 | if (!constraints.Any())
37 | {
38 | continue;
39 | }
40 |
41 | if (constraints.Length > 1)
42 | {
43 | throw new NotSupportedException("not support multiple constrants");
44 | }
45 |
46 | item.TypeConstraint = constraints[0].Type;
47 |
48 | }
49 | }
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/YieldStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp;
9 | using RoslynTypeScript.Constants;
10 |
11 | namespace RoslynTypeScript.Translation
12 | {
13 | public class YieldStatementTranslation : StatementTranslation
14 | {
15 | public new YieldStatementSyntax Syntax
16 | {
17 | get { return (YieldStatementSyntax)base.Syntax; }
18 | set { base.Syntax = value; }
19 | }
20 |
21 | public YieldStatementTranslation() { }
22 | public YieldStatementTranslation(YieldStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Expression = syntax.Expression.Get(this);
25 | }
26 |
27 | public override void ApplyPatch()
28 | {
29 | if (Syntax.IsKind(SyntaxKind.YieldReturnStatement))
30 | {
31 | var method = this.GetAncestor();
32 | if (method != null)
33 | {
34 | method.IsYieldReturn = true;
35 | }
36 | }
37 |
38 | base.ApplyPatch();
39 | }
40 |
41 | public ExpressionTranslation Expression { get; set; }
42 |
43 | protected override string InnerTranslate()
44 | {
45 | if (Syntax.IsKind(SyntaxKind.YieldReturnStatement))
46 | {
47 | var expr = Expression.Translate();
48 |
49 | return $@"{TC.YieldResultName}.push({expr});
50 | /*{Syntax.ToString()}*/";
51 | }
52 |
53 | return Syntax.ToString();
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TypescriptSyntaxPaste
2 |
3 | - Visual Studio Extension which converts C# SYNTAX to Typescript SYNTAX, you just need to Copy C# code, and paste into Typescript.ts source code.
4 |
5 | - There is option which will convert class/struct to Typescript interface. (In VS 2015 goto Tool->Option->Typescript Paste-> Convert to interface:true)
6 |
7 | **HOW TO DEBUG/RUN.**
8 |
9 | Need Visual Studio 2015 + install VS 2015 SDK to compile and run this extension.
10 | Then you need to configure project to allow you debug with VS 2015: go to project Property, Debug tab ->
11 | - Select Start External Program, and fill your VS2015 path (example: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe)
12 | - Command line arguments: /rootsuffix Exp
13 |
14 | **BRIEF CODE INFORMATION**
15 |
16 | Almost all converting classes are in folder Translation, which for each file containing the convert method to convert one kind of
17 | syntax (C#) to Typescript. For example ````ClassDeclarationSyntax```` in Roslyn will be ````ClassDeclarationTranslation```` in this project.
18 |
19 | Let say you want convert :
20 | in C#: ````class A {}````
21 | typescript: ````class myA{}````
22 |
23 | you just need to navigate to class ClassDeclarationTranslation in project, then change this line:
24 | ````
25 | return $@"{GetAttributeList()}export class {Syntax.Identifier}{TypeParameterList?.Translate()} {baseTranslation}
26 | {{
27 | {Members.Translate()}
28 | }}";
29 | ````
30 | to:
31 | ````
32 | return $@"{GetAttributeList()}export class my{Syntax.Identifier}{TypeParameterList?.Translate()} {baseTranslation}
33 | {{
34 | {Members.Translate()}
35 | }}";
36 | ````
37 |
38 | For more information about Syntax Tree in Roslyn, you can use Syntax Visualizer which is included in VS 2015 (View -> Other Windows-> Syntax Visualizer) or online version: http://bdnprojects.net/CSharpSyntaxParser/
39 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/StructDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using RoslynTypeScript.Patch;
9 | using RoslynTypeScript.Contract;
10 | using RoslynTypeScript.Constants;
11 |
12 | namespace RoslynTypeScript.Translation
13 | {
14 | public class StructDeclarationTranslation : ClassStructDeclarationTranslation, IBaseExtended
15 | {
16 | public new StructDeclarationSyntax Syntax
17 | {
18 | get { return (StructDeclarationSyntax)base.Syntax; }
19 | set { base.Syntax = value; }
20 | }
21 | //public StructDeclarationTranslation() { }
22 | public StructDeclarationTranslation(StructDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | if(BaseList == null)
25 | {
26 | BaseList = new BaseListTranslation();
27 | BaseList.Parent = this;
28 | BaseList.Types = new SeparatedSyntaxListTranslation();
29 | BaseList.Types.Parent = BaseList;
30 | }
31 |
32 | //BaseList.Types.Add(new BaseTypeTranslation() { SyntaxString = TC.IStruct });
33 | }
34 |
35 |
36 | public override void ApplyPatch()
37 | {
38 | base.ApplyPatch();
39 | //StructPatch structPatch = new StructPatch();
40 | //structPatch.Apply(this);
41 | }
42 |
43 | protected override string InnerTranslate()
44 | {
45 | string baseTranslation = BaseList?.Translate();
46 |
47 | return $@"{GetAttributeList()}export class {Syntax.Identifier}{TypeParameterList?.Translate()} {baseTranslation}
48 | {{
49 | {Members.Translate()}
50 | }}";
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SizeOfExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class SizeOfExpressionTranslation : ExpressionTranslation
12 | {
13 | public new SizeOfExpressionSyntax Syntax
14 | {
15 | get { return (SizeOfExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public SizeOfExpressionTranslation() { }
20 | public SizeOfExpressionTranslation(SizeOfExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Type = syntax.Type.Get(this);
23 | }
24 |
25 | public TypeTranslation Type { get; set; }
26 |
27 | protected override string InnerTranslate()
28 | {
29 | var semanticModel = GetSemanticModel();
30 | var type = semanticModel.GetTypeInfo(Syntax.Type);
31 | if (type.Type != null)
32 | {
33 | switch (type.Type.SpecialType)
34 | {
35 | case SpecialType.System_Byte:
36 | case SpecialType.System_SByte:
37 | return "1";
38 | case SpecialType.System_Int16:
39 | case SpecialType.System_UInt16:
40 | return "2";
41 | case SpecialType.System_Int32:
42 | case SpecialType.System_UInt32:
43 | return "4";
44 | case SpecialType.System_Int64:
45 | case SpecialType.System_UInt64:
46 | return "8";
47 |
48 | }
49 | }
50 |
51 | return $"__sizeof__({Syntax.Type.ToString()})";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ObjectCreationExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ObjectCreationExpressionTranslation : ExpressionTranslation
12 | {
13 | public new ObjectCreationExpressionSyntax Syntax
14 | {
15 | get { return (ObjectCreationExpressionSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public ObjectCreationExpressionTranslation() { }
19 | public ObjectCreationExpressionTranslation(ObjectCreationExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | ArgumentList = syntax.ArgumentList.Get(this);
22 | Initializer = syntax.Initializer.Get(this);
23 | Type = syntax.Type.Get(this);
24 | }
25 |
26 | public ArgumentListTranslation ArgumentList { get; set; }
27 | public InitializerExpressionTranslation Initializer { get; set; }
28 | public TypeTranslation Type { get; set; }
29 |
30 | protected override string InnerTranslate()
31 | {
32 | var name = Type.Translate();
33 |
34 | // the case object creation only by Initializer
35 | if(ArgumentList == null)
36 | {
37 | ArgumentList = new ArgumentListTranslation()
38 | {
39 | Parent = this,
40 | SyntaxString = "()"
41 | };
42 | }
43 |
44 |
45 | if (Initializer == null )
46 | {
47 |
48 | return $"new {Type.Translate()} {ArgumentList.Translate()}";
49 | }
50 |
51 | return $" __init(new {Type.Translate()} {ArgumentList.Translate()},{Initializer.Translate()})";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/QualifiedNameTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class QualifiedNameTranslation : NameTranslation
12 | {
13 | public new QualifiedNameSyntax Syntax
14 | {
15 | get { return (QualifiedNameSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public QualifiedNameTranslation(QualifiedNameSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | Left = syntax.Left.Get(this);
22 | Right = syntax.Right.Get(this);
23 |
24 | var genericTranslation = Left as GenericNameTranslation;
25 | if (genericTranslation != null)
26 | {
27 | ((GenericNameTranslation)Left).ExcludeTypeParameter = true;
28 |
29 | }
30 |
31 | var simpleName = Right as SimpleNameTranslation;
32 | if (simpleName != null)
33 | {
34 | simpleName.DetectApplyThis = false;
35 | var identifierName = simpleName as IdentifierNameTranslation;
36 | if (genericTranslation != null && identifierName!=null)
37 | {
38 | identifierName.TypeArgumentList = genericTranslation.TypeArgumentList;
39 | }
40 |
41 | }
42 | }
43 |
44 | public override string GetTypeIgnoreGeneric()
45 | {
46 | return $"{Left.GetTypeIgnoreGeneric()}.{Right.Translate()}";
47 | }
48 |
49 | public NameTranslation Left { get; set; }
50 | public SimpleNameTranslation Right { get; set; }
51 |
52 | protected override string InnerTranslate()
53 | {
54 | return $"{Left.Translate()}.{Right.Translate()}";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SyntaxNodeExtensions.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public static class SyntaxNodeExtensions
12 | {
13 | public static CompilationUnitTranslation GetCompilationUnit(this CompilationUnitSyntax syntax)
14 | {
15 | return new CompilationUnitTranslation(syntax, null);
16 | }
17 |
18 | public static T Get(this SyntaxNode syntaxNode, SyntaxTranslation parent) where T : SyntaxTranslation
19 | {
20 | if (syntaxNode == null)
21 | {
22 | return null;
23 | }
24 |
25 | var node = TF.Get(syntaxNode, parent);
26 | return node;
27 | }
28 |
29 | public static SyntaxTokenListTranslation Get(this SyntaxTokenList list, SyntaxTranslation parent)
30 | {
31 | var newList = new SyntaxTokenListTranslation(list, parent);
32 | return newList;
33 | }
34 |
35 | public static SyntaxListTranslation Get(this SyntaxList syntaxList, SyntaxTranslation parent) where T : SyntaxNode where TS : SyntaxTranslation
36 | {
37 | var newList = new SyntaxListTranslation(syntaxList, parent);
38 | return newList;
39 | }
40 |
41 | public static SeparatedSyntaxListTranslation Get(this SeparatedSyntaxList syntaxList, SyntaxTranslation parent) where T : SyntaxNode where TS : SyntaxTranslation
42 | {
43 | var newList = new SeparatedSyntaxListTranslation(syntaxList, parent);
44 | return newList;
45 | }
46 |
47 | public static TokenTranslation Get(this SyntaxToken token, SyntaxTranslation parent)
48 | {
49 | var newToken = new TokenTranslation(token, parent);
50 | return newToken;
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/CompilationalUnitTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class CompilationUnitTranslation : SyntaxTranslation
12 | {
13 | private SemanticModel semanticModel;
14 |
15 | public new CompilationUnitSyntax Syntax
16 | {
17 | get { return (CompilationUnitSyntax)base.Syntax; }
18 | set { base.Syntax = value; }
19 | }
20 |
21 | public SyntaxListTranslation Members { get; set; }
22 |
23 | public CompilationUnitTranslation(CompilationUnitSyntax syntax, SyntaxTranslation parent) : base(syntax, null)
24 | {
25 | //Compilation = compilation;
26 | //this.semanticModel = semanticModel;
27 | Members = syntax.Members.Get(this);
28 | }
29 |
30 | public Solution Solution { get; set; }
31 |
32 | public Compilation Compilation { get; set; }
33 |
34 | public List GotoLabeledStatements { get; set; } = new List();
35 | public List ContinueStatements { get; set; } = new List();
36 |
37 | public SemanticModel SemanticModel
38 | {
39 | get
40 | {
41 | if (semanticModel == null)
42 | {
43 | semanticModel = Compilation.GetSemanticModel(Syntax.SyntaxTree);
44 | }
45 |
46 | return semanticModel;
47 | }
48 | set
49 | {
50 | semanticModel = value;
51 | }
52 | }
53 |
54 | protected override string InnerTranslate()
55 | {
56 | return Members.Translate();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ForStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ForStatementTranslation : StatementTranslation
12 | {
13 | public new ForStatementSyntax Syntax
14 | {
15 | get { return (ForStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ForStatementTranslation() { }
20 | public ForStatementTranslation(ForStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | //KeyValuePair? a = null;
23 | //var b = ((bool?)null)?.Equals(false) ?? true ? false ? true : false :true;
24 |
25 | //string str = "\{ ("\{( "(\{ "{}" })" )}") }";
26 |
27 | Condition = syntax.Condition.Get(this);
28 | Declaration = syntax.Declaration.Get(this);
29 | Incrementors = syntax.Incrementors.Get(this);
30 | Initializers = syntax.Initializers.Get(this);
31 | Statement = syntax.Statement.Get(this);
32 | }
33 |
34 | public ExpressionTranslation Condition { get; set; }
35 | public VariableDeclarationTranslation Declaration { get; set; }
36 | public SeparatedSyntaxListTranslation Incrementors { get; set; }
37 | public SeparatedSyntaxListTranslation Initializers { get; set; }
38 | public StatementTranslation Statement { get; }
39 |
40 | protected override string InnerTranslate()
41 | {
42 | return $@"for({Declaration?.Translate()};{Condition?.Translate()};{Incrementors?.Translate()})
43 | {Statement.Translate()}";
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/OperatorDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using RoslynTypeScript.Constants;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class OperatorDeclarationTranslation : BaseMethodDeclarationTranslation
13 | {
14 | public new OperatorDeclarationSyntax Syntax
15 | {
16 | get { return (OperatorDeclarationSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public OperatorDeclarationTranslation() { }
21 | public OperatorDeclarationTranslation(OperatorDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | ReturnType = syntax.ReturnType.Get(this);
24 | Identifier = new TokenTranslation { SyntaxString = Helper.OperatorToMethod(syntax.OperatorToken.ToString()) };
25 | }
26 |
27 | //public ArrowExpressionClauseSyntax ExpressionBody { get; set; }
28 |
29 | public TypeTranslation ReturnType { get; set; }
30 |
31 |
32 | protected override string InnerTranslate()
33 | {
34 |
35 | // currently, I only support == != > < >= <=
36 | string originalOpeartor = Syntax.OperatorToken.ToString();
37 | if(!Helper.IsSupportOperator(originalOpeartor))
38 | {
39 | throw new NotSupportedException();
40 | }
41 |
42 | // this is static method -> to normal method
43 | var firstParam = ParameterList.Parameters.GetEnumerable().First();
44 | string firstParamStr = firstParam.Identifier.Translate();
45 | ParameterList.Parameters.Remove(firstParam);
46 | return $@" public {Identifier} {ParameterList}: {ReturnType}
47 | {{
48 | var {firstParamStr} = this;
49 | {Body.Statements.Translate()}
50 | }}
51 | ";
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | TypescriptSyntaxPaste
6 | Allow you to copy C# source code, then paste as Typescript syntax which help you with converting DTO or interface.
7 | Copy any C# code (correct syntax, whole class, method or interface, currently does not support to convert fragment of source code)
8 | It is based on Roslyn compiler, and simply only convert to the Typescript syntax. (without semantic information)
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPasteSolution.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypescriptSyntaxPaste", "TypescriptSyntaxPaste\TypescriptSyntaxPaste.csproj", "{9FE49593-3450-441F-AB64-02DEF912B9B1}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypescriptSyntaxPaste.Tests", "TypescriptSyntaxPaste.Tests\TypescriptSyntaxPaste.Tests.csproj", "{2D69301B-A90B-4601-8330-A9A908332744}"
9 | EndProject
10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypescriptSyntaxPaste.Console", "TypescriptSyntaxPaste.Console\TypescriptSyntaxPaste.Console.csproj", "{0155F584-BD9C-4D25-B3F6-D99D8772F030}"
11 | EndProject
12 | Global
13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
14 | Debug|Any CPU = Debug|Any CPU
15 | Release|Any CPU = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {9FE49593-3450-441F-AB64-02DEF912B9B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19 | {9FE49593-3450-441F-AB64-02DEF912B9B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
20 | {9FE49593-3450-441F-AB64-02DEF912B9B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
21 | {9FE49593-3450-441F-AB64-02DEF912B9B1}.Release|Any CPU.Build.0 = Release|Any CPU
22 | {2D69301B-A90B-4601-8330-A9A908332744}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23 | {2D69301B-A90B-4601-8330-A9A908332744}.Debug|Any CPU.Build.0 = Debug|Any CPU
24 | {2D69301B-A90B-4601-8330-A9A908332744}.Release|Any CPU.ActiveCfg = Release|Any CPU
25 | {2D69301B-A90B-4601-8330-A9A908332744}.Release|Any CPU.Build.0 = Release|Any CPU
26 | {0155F584-BD9C-4D25-B3F6-D99D8772F030}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27 | {0155F584-BD9C-4D25-B3F6-D99D8772F030}.Debug|Any CPU.Build.0 = Debug|Any CPU
28 | {0155F584-BD9C-4D25-B3F6-D99D8772F030}.Release|Any CPU.ActiveCfg = Release|Any CPU
29 | {0155F584-BD9C-4D25-B3F6-D99D8772F030}.Release|Any CPU.Build.0 = Release|Any CPU
30 | EndGlobalSection
31 | GlobalSection(SolutionProperties) = preSolution
32 | HideSolutionNode = FALSE
33 | EndGlobalSection
34 | EndGlobal
35 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/VariableDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class VariableDeclarationTranslation : CSharpSyntaxTranslation
12 | {
13 | public new VariableDeclarationSyntax Syntax
14 | {
15 | get { return (VariableDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public TypeTranslation Type { get; set; }
19 | public SeparatedSyntaxListTranslation Variables { get; set; }
20 |
21 |
22 | public VariableDeclarationTranslation(VariableDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Type = syntax.Type.Get(this);
25 | Variables = syntax.Variables.Get(this);
26 | if (!syntax.Type.IsVar)
27 | {
28 | Variables.GetEnumerable().First().FirstType = Type;
29 | }
30 |
31 | foreach (var item in Variables.GetEnumerable())
32 | {
33 | item.KnownType = Type;
34 | }
35 | }
36 |
37 | public bool ExcludeVar { get; set; }
38 |
39 | //private bool isIgnoreInitialize;
40 | //public bool IsIgnoreInitialize
41 | //{
42 | // get { return isIgnoreInitialize; }
43 | // set {
44 | // isIgnoreInitialize = value;
45 | // foreach (var item in Variables.GetEnumerable())
46 | // {
47 | // item.IsIgnoreInitialize = value;
48 | // }
49 | // }
50 | //}
51 |
52 | protected override string InnerTranslate()
53 | {
54 | if (ExcludeVar)
55 | return string.Format("{0}", Variables.Translate());
56 | return string.Format("var {0}", Variables.Translate());
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/BaseMethodDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public abstract class BaseMethodDeclarationTranslation : MemberDeclarationTranslation
12 | {
13 | public new BaseMethodDeclarationSyntax Syntax
14 | {
15 | get { return (BaseMethodDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 | public BaseMethodDeclarationTranslation() { }
19 | public BaseMethodDeclarationTranslation(BaseMethodDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
20 | {
21 | ParameterList = syntax.ParameterList.Get(this);
22 | Modifiers = syntax.Modifiers.Get(this);
23 | Body = syntax.Body.Get(this);
24 | SemicolonToken = syntax.SemicolonToken.Get(this);
25 | }
26 |
27 |
28 | public ParameterListTranslation ParameterList { get; set; }
29 | public SyntaxTokenListTranslation Modifiers { get; set; }
30 | public BlockTranslation Body { get; set; }
31 | public TokenTranslation SemicolonToken { get; set; }
32 | public TokenTranslation Identifier { get; set; }
33 |
34 | public bool IsTheSameOverloading(BaseMethodDeclarationTranslation method)
35 | {
36 | var sameToken = this.Identifier.TokenEquals(method.Identifier);
37 | if (!sameToken) return false;
38 | return method.Modifiers.IsStatic == this.Modifiers.IsStatic;
39 | }
40 |
41 | public override void ApplyPatch()
42 | {
43 | base.ApplyPatch();
44 | }
45 |
46 | protected override string InnerTranslate()
47 | {
48 | return Syntax.ToString();
49 | }
50 |
51 | protected string GetAttributeList()
52 | {
53 | return Helper.GetAttributeList(Syntax.AttributeLists);
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/PropertyDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class PropertyDeclarationTranslation : BasePropertyDeclarationTranslation
12 | {
13 | public new PropertyDeclarationSyntax Syntax
14 | {
15 | get { return (PropertyDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public TokenTranslation Identifier { get; set; }
20 |
21 |
22 | public PropertyDeclarationTranslation(PropertyDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
23 | {
24 | Identifier = syntax.Identifier.Get(this);
25 | }
26 |
27 |
28 | protected override string InnerTranslate()
29 | {
30 | var found = TravelUp(f => f is ClassDeclarationTranslation || f is InterfaceDeclarationTranslation);
31 |
32 | // following TypeScript with interface, we just need set as Field
33 | if (found is InterfaceDeclarationTranslation)
34 | {
35 | //return string.Format("{0}: {1}", syntax.Identifier,type.Translate());
36 | return $"{Helper.GetAttributeList(Syntax.AttributeLists)}{Syntax.Identifier}: {Type.Translate()} ;";
37 | }
38 |
39 | // hmm, if it's in class, much thing to do
40 |
41 | if (AccessorList.IsShorten())
42 | {
43 |
44 | var defaultStr = Helper.GetDefaultValue(Type);
45 | if (defaultStr == "null")
46 | {
47 | defaultStr = string.Empty;
48 | }
49 | else
50 | {
51 | defaultStr = " = " + defaultStr;
52 | }
53 | return $"{Helper.GetAttributeList(Syntax.AttributeLists)} {Modifiers.Translate()} {Syntax.Identifier}: {Type.Translate()}{defaultStr} ;";
54 | }
55 |
56 | return AccessorList.Translate();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/TypeDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using RoslynTypeScript.Contract;
4 | using RoslynTypeScript.Patch;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace RoslynTypeScript.Translation
12 | {
13 | public abstract class TypeDeclarationTranslation : BaseTypeDeclarationTranslation, ITypeParameterConstraint
14 | {
15 | public new TypeDeclarationSyntax Syntax
16 | {
17 | get { return (TypeDeclarationSyntax)base.Syntax; }
18 | set { base.Syntax = value; }
19 | }
20 |
21 | public TypeDeclarationTranslation(TypeDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | TypeParameterList = syntax.TypeParameterList.Get(this);
24 | Members = syntax.Members.Get(this);
25 | ConstraintClauses = syntax.ConstraintClauses.Get(this);
26 | }
27 |
28 | public SyntaxListTranslation Members { get; set; }
29 |
30 | public SyntaxListTranslation ConstraintClauses { get; set; }
31 |
32 | public TypeParameterListTranslation TypeParameterList { get; set; }
33 |
34 | public TokenTranslation Identifier
35 | {
36 | get { return Syntax.Identifier.Get(this); }
37 | }
38 |
39 | public override void ApplyPatch()
40 | {
41 | GenericConstrantsPatch genericConstrantsPatch = new GenericConstrantsPatch();
42 | genericConstrantsPatch.Apply(this);
43 | base.ApplyPatch();
44 | /// OverloadingPatch patch = new OverloadingPatch();
45 | // patch.Apply(this);
46 | }
47 |
48 | protected string GetAttributeList()
49 | {
50 | return Helper.GetAttributeList(Syntax.AttributeLists);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/MakeMemberCamelCase.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis;
9 |
10 | namespace TypescriptSyntaxPaste
11 | {
12 |
13 | class MemberToCamelCaseRewriter:CSharpSyntaxRewriter
14 | {
15 | public override SyntaxNode VisitPropertyDeclaration(PropertyDeclarationSyntax propertySyntax)
16 | {
17 | var leadingTrivia = propertySyntax.Identifier.LeadingTrivia;
18 | var trailingTriva = propertySyntax.Identifier.TrailingTrivia;
19 | return propertySyntax.ReplaceToken(propertySyntax.Identifier,
20 | SyntaxFactory.Identifier(leadingTrivia,
21 | ToCamelCase(propertySyntax.Identifier.ValueText), trailingTriva) );
22 | }
23 |
24 | public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax methodSyntax)
25 | {
26 | var leadingTrivia = methodSyntax.Identifier.LeadingTrivia;
27 | var trailingTriva = methodSyntax.Identifier.TrailingTrivia;
28 | return methodSyntax.ReplaceToken(methodSyntax.Identifier,
29 | SyntaxFactory.Identifier(leadingTrivia, ToCamelCase(methodSyntax.Identifier.ValueText), trailingTriva));
30 | }
31 |
32 | public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax fieldSyntax)
33 | {
34 | return fieldSyntax.ReplaceTokens(fieldSyntax.Declaration.Variables.Select(f => f.Identifier),
35 | (t1, t2) => SyntaxFactory.Identifier(t1.LeadingTrivia, ToCamelCase(t1.ValueText), t1.TrailingTrivia));
36 |
37 | }
38 |
39 | private static string ToCamelCase(string name)
40 | {
41 | return name.Substring(0, 1).ToLower() + name.Substring(1);
42 | }
43 | }
44 |
45 | public class MakeMemberCamelCase
46 | {
47 | public static CSharpSyntaxNode Make(CSharpSyntaxNode syntaxNode)
48 | {
49 |
50 | var rewriter = new MemberToCamelCaseRewriter();
51 | return (CSharpSyntaxNode)rewriter.Visit(syntaxNode);
52 | }
53 |
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/InitializerExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class InitializerExpressionTranslation : ExpressionTranslation
13 | {
14 | public new InitializerExpressionSyntax Syntax
15 | {
16 | get { return (InitializerExpressionSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public InitializerExpressionTranslation() { }
21 | public InitializerExpressionTranslation(InitializerExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
22 | {
23 | Expressions = syntax.Expressions.Get(this);
24 | }
25 |
26 | public SeparatedSyntaxListTranslation Expressions { get; set; }
27 |
28 |
29 | public override void ApplyPatch()
30 | {
31 | base.ApplyPatch();
32 | if (Syntax.IsKind(SyntaxKind.ArrayInitializerExpression))
33 | {
34 | return;
35 | }
36 |
37 | foreach (var item in Expressions.GetEnumerable())
38 | {
39 | var exp = item as AssignmentExpressionTranslation;
40 | if(exp == null)
41 | {
42 | continue;
43 | }
44 |
45 | var identifierName = exp.Left as IdentifierNameTranslation;
46 | if(identifierName == null)
47 | {
48 | continue;
49 | }
50 |
51 | identifierName.DetectApplyThis = false;
52 |
53 | exp.OverrideOpeartor = ":";
54 | }
55 | }
56 |
57 | protected override string InnerTranslate()
58 | {
59 | if (Syntax.IsKind(SyntaxKind.ArrayInitializerExpression))
60 | {
61 | return $"[ {Expressions.Translate()} ]"; ;
62 | }
63 | return $"{{ {Expressions.Translate()} }}";
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/SyntaxTranslationFactory.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp.Syntax;
9 |
10 |
11 | namespace RoslynTypeScript.Translation
12 | {
13 | public static class TF
14 | {
15 | private static Dictionary _mapType = new Dictionary();
16 |
17 | static TF()
18 | {
19 | }
20 |
21 | public static T Get(SyntaxNode syntaxNode, SyntaxTranslation parent) where T : SyntaxTranslation
22 | {
23 | return (T)Get(syntaxNode, parent);
24 | }
25 |
26 | public static T VirtualGet(string code) where T : SyntaxTranslation, new()
27 | {
28 | return new T() { SyntaxString = code };
29 | }
30 |
31 | public static SyntaxTranslation Get(SyntaxNode node, SyntaxTranslation parent)
32 | {
33 | Type type = node.GetType();
34 | Type newType = FindMatchedType(type);
35 |
36 | SyntaxTranslation translation = (SyntaxTranslation)Activator.CreateInstance(newType, node, parent);
37 | return translation;
38 | }
39 |
40 | private static Type FindMatchedType(Type type)
41 | {
42 | if(_mapType.ContainsKey(type))
43 | {
44 | return _mapType[type];
45 | }
46 | Assembly assembly = typeof(TF).Assembly;
47 | var newType = assembly.GetType(GetTranslationName(type.Name));
48 | if (newType == null)
49 | {
50 | return typeof(GenericTranslation);
51 | }
52 |
53 | return newType;
54 | }
55 |
56 |
57 | private static string GetTranslationName(string syntaxNodeName)
58 | {
59 | string name = syntaxNodeName.Remove(syntaxNodeName.Length - 6);
60 | return "RoslynTypeScript.Translation." + name + "Translation";
61 | }
62 |
63 | public static void RegisterType()
64 | where TSyntax :SyntaxNode
65 | where TTransaltion :SyntaxTranslation
66 | {
67 | _mapType[typeof(TSyntax)] = typeof(TTransaltion);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/InvocationExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.CodeAnalysis.CSharp.Syntax;
4 | using RoslynTypeScript.Patch;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace RoslynTypeScript.Translation
12 | {
13 | public class InvocationExpressionTranslation : ExpressionTranslation
14 | {
15 | public new InvocationExpressionSyntax Syntax
16 | {
17 | get { return (InvocationExpressionSyntax)base.Syntax; }
18 | set { base.Syntax = value; }
19 | }
20 |
21 | public ExpressionTranslation Expression { get; set; }
22 | public ArgumentListTranslation ArgumentList { get; set; }
23 |
24 | public InvocationExpressionTranslation() { }
25 |
26 | public InvocationExpressionTranslation(InvocationExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
27 | {
28 | Expression = syntax.Expression.Get(this);
29 | ArgumentList = syntax.ArgumentList.Get(this);
30 | if (Expression is MemberAccessExpressionTranslation)
31 | {
32 | var memberAccess = (MemberAccessExpressionTranslation)Expression;
33 | memberAccess.IsInInvocation = true;
34 | }
35 | }
36 |
37 | public override void ApplyPatch()
38 | {
39 | base.ApplyPatch();
40 | }
41 |
42 |
43 | protected override string InnerTranslate()
44 | {
45 | var invocationName = Syntax.Expression.ToString();
46 | if (invocationName.EndsWith("ReferenceEquals"))
47 | {
48 | return $"ReferenceEquals{ArgumentList.Translate()}";
49 | }
50 |
51 | var name = this.Syntax.Expression.ToString();
52 |
53 | if (Expression is MemberAccessExpressionTranslation)
54 | {
55 | var memberAccess = (MemberAccessExpressionTranslation)Expression;
56 | memberAccess.IsInInvocation = true;
57 |
58 | }
59 |
60 | return string.Format("{0}{1}", Expression.Translate(), ArgumentList.Translate());
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Patch/InnerTypeDeclarationPatch.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis.CSharp.Syntax;
2 | using RoslynTypeScript.Translation;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Patch
10 | {
11 | ///
12 | /// put the nested class into the correct structure of Typescript, which we must create
13 | /// another module
14 | ///
15 | public class InnerTypeDeclarationPatch : Patch
16 | {
17 | public void Apply(BaseTypeDeclarationTranslation typeDeclarationTranslation)
18 | {
19 | // TODO: only support one level, why do you need nested > 1 level ?
20 | TypeDeclarationTranslation outerMemberDeclaration =
21 | (TypeDeclarationTranslation)typeDeclarationTranslation.TravelUpNotMe(f => f is TypeDeclarationTranslation);
22 | if(outerMemberDeclaration==null)
23 | {
24 | return;
25 | }
26 |
27 | SyntaxListBaseTranslation syntaxListBaseTranslation = (SyntaxListBaseTranslation)typeDeclarationTranslation.Parent;
28 |
29 | syntaxListBaseTranslation.Remove(typeDeclarationTranslation);
30 |
31 | SyntaxListBaseTranslation outerSyntaxListBaseTranslation = (SyntaxListBaseTranslation)outerMemberDeclaration.Parent;
32 | var newNamespace = CreateNewNamespace(outerMemberDeclaration.Syntax.Identifier.ToString(), typeDeclarationTranslation);
33 | outerSyntaxListBaseTranslation.Add(newNamespace);
34 |
35 | }
36 |
37 | private NamespaceDeclarationTranslation CreateNewNamespace(string identifier, BaseTypeDeclarationTranslation typeDeclarationTranslation)
38 | {
39 | NamespaceDeclarationTranslation newNamespaceTranslation = new NamespaceDeclarationTranslation();
40 | newNamespaceTranslation.Name = new IdentifierNameTranslation() { SyntaxString = identifier, Parent = newNamespaceTranslation };
41 | newNamespaceTranslation.Members = new SyntaxListTranslation() { Parent = newNamespaceTranslation };
42 | newNamespaceTranslation.Members.Add(typeDeclarationTranslation);
43 | newNamespaceTranslation.IsExport = true;
44 |
45 | return newNamespaceTranslation;
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/SeparatedSyntaxListTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RoslynTypeScript.Translation
9 | {
10 | public class SeparatedSyntaxListTranslation : SyntaxListBaseTranslation where T : SyntaxNode where ST : SyntaxTranslation
11 | {
12 | private SeparatedSyntaxList separatedSyntaxList;
13 |
14 | public SeparatedSyntaxListTranslation()
15 | {
16 | SyntaxCollection = new List();
17 | }
18 |
19 | public SeparatedSyntaxListTranslation(SeparatedSyntaxList separatedSyntaxList, SyntaxTranslation parent) :base(parent)
20 | {
21 | this.separatedSyntaxList = separatedSyntaxList;
22 | this.Parent = parent;
23 | SyntaxCollection = separatedSyntaxList.Select(f => f.Get(this)).ToList();
24 | }
25 |
26 | public bool IsNewLine { get; set; }
27 | public string Seperator { get; set; }
28 |
29 | protected override string InnerTranslate()
30 | {
31 | if (!SyntaxCollection.Any())
32 | {
33 | return string.Empty;
34 | }
35 |
36 | StringBuilder bd = new StringBuilder();
37 |
38 | //int separatorCount = separatedSyntaxList.GetSeparators().Count();
39 | int separatorCount = SyntaxCollection.Count - 1;
40 | for (int i = 0; i < SyntaxCollection.Count; i++)
41 | {
42 | bd.Append(SyntaxCollection[i].Translate());
43 | if (i < separatorCount)
44 | {
45 | bd.Append(Seperator?? GetSeparator(i));
46 | if (IsNewLine)
47 | {
48 | bd.Append(Environment.NewLine);
49 | }
50 | }
51 |
52 | }
53 |
54 | return bd.ToString();
55 | //return string.Join(",", SyntaxCollection.Select(f => f.Translate()));
56 | }
57 |
58 | private string GetSeparator(int idx)
59 | {
60 | var separator = separatedSyntaxList.GetSeparator(idx);
61 | return $"{Helper.GetNewLineIfExist(separator.LeadingTrivia)}{separator.ToString()}{Helper.GetNewLineIfExist(separator.TrailingTrivia)}";
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Patch/FieldInitializePatch.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using Microsoft.CodeAnalysis.CSharp.Syntax;
7 | using RoslynTypeScript.Translation;
8 |
9 | namespace RoslynTypeScript.Patch
10 | {
11 | ///
12 | /// Not using at this moment!!!!
13 | /// try to find constructor and set default value for field which is number, boolean. Because
14 | /// in javascript all fields are undefined at the first place.
15 | ///
16 | public class FieldInitializePatch : Patch
17 | {
18 | public void Apply(ClassDeclarationTranslation typeTranslation)
19 | {
20 | var fields = typeTranslation.Members.GetEnumerable();
21 | if (!fields.Any())
22 | {
23 | return;
24 | }
25 |
26 | ConstructorDeclarationTranslation constructor = FindConstructor(typeTranslation);
27 | if (constructor == null)
28 | {
29 | return;
30 | }
31 |
32 | if (!typeTranslation.HasExplicitBase())
33 | {
34 | return;
35 | }
36 |
37 | foreach (FieldDeclarationTranslation field in fields)
38 | {
39 | if (field.Modifiers.IsStatic)
40 | {
41 | continue;
42 | }
43 |
44 | AssignmentExpressionTranslation assignment = BuildAssignment(field);
45 | constructor.Body.Statements.Insert(0, assignment);
46 | }
47 | }
48 |
49 | private ConstructorDeclarationTranslation FindConstructor(TypeDeclarationTranslation typeTranslation)
50 | {
51 | var constructor = typeTranslation.Members.GetEnumerable().FirstOrDefault(f => !f.IsDeclarationOverload);
52 | return constructor;
53 | }
54 |
55 | private AssignmentExpressionTranslation BuildAssignment(FieldDeclarationTranslation field)
56 | {
57 | var declarator = field.Declaration.Variables.GetEnumerable().First();
58 | var initializeStr = declarator.GetInitializerStr();
59 | string statement = $"this.{declarator.Identifier.Translate()}{initializeStr};";
60 | return new AssignmentExpressionTranslation() { SyntaxString = statement };
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Tests/ConvertHelper.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp;
3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
4 | using RoslynTypeScript.Translation;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace TypescriptSyntaxPaste.Tests
12 | {
13 | public static class ConvertHelper
14 | {
15 | public static string ConvertToTypescript(string csharpCode, IEnumerable< Func> funcs = null)
16 | {
17 | var mscorlib = MetadataReference.CreateFromFile(typeof(object).Assembly.Location);
18 | var tree = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(csharpCode);
19 |
20 | if (tree.GetDiagnostics().Any(f => f.Severity == DiagnosticSeverity.Error))
21 | {
22 | return null;
23 | }
24 |
25 | var root = tree.GetRoot();
26 |
27 | if (funcs != null)
28 | {
29 | foreach (var func in funcs)
30 | {
31 | root = func(root);
32 | }
33 |
34 | }
35 |
36 | var translationNode = TF.Get(root, null);
37 |
38 | var compilation = CSharpCompilation.Create("TemporaryCompilation",
39 | syntaxTrees: new[] { tree }, references: new[] { mscorlib });
40 | var model = compilation.GetSemanticModel(tree);
41 |
42 | translationNode.Compilation = compilation;
43 | translationNode.SemanticModel = model;
44 |
45 | translationNode.ApplyPatch();
46 | return translationNode.Translate();
47 | }
48 |
49 | public static void AssertConvertingIgnoreSpaces(string csharpCode, string typescriptCode,IEnumerable< Func> funcs = null)
50 | {
51 | var stripTypescriptCode = StripAllSpaces(typescriptCode);
52 | var converted = ConvertToTypescript(csharpCode, funcs);
53 |
54 | Assert.AreEqual(stripTypescriptCode, StripAllSpaces(converted));
55 | }
56 |
57 | private static string StripAllSpaces(string code)
58 | {
59 | if (code == null)
60 | {
61 | return string.Empty;
62 | }
63 |
64 | return code.Replace(" ", "").Replace("\n", "").Replace("\r", "").Replace("\t", "");
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/MemberAccessExpressionTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 | using Microsoft.CodeAnalysis.CSharp;
9 |
10 | namespace RoslynTypeScript.Translation
11 | {
12 | public class MemberAccessExpressionTranslation : ExpressionTranslation
13 | {
14 | public new MemberAccessExpressionSyntax Syntax
15 | {
16 | get { return (MemberAccessExpressionSyntax)base.Syntax; }
17 | set { base.Syntax = value; }
18 | }
19 |
20 | public ExpressionTranslation Expression { get; set; }
21 | public SimpleNameTranslation Name { get; set; }
22 |
23 | public bool IsInInvocation { get; set; }
24 |
25 | public MemberAccessExpressionTranslation(MemberAccessExpressionSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
26 | {
27 | Expression = syntax.Expression.Get(this);
28 | Name = syntax.Name.Get(this);
29 |
30 | var simpleName = Name as SimpleNameTranslation;
31 |
32 | if (simpleName != null)
33 | {
34 | simpleName.DetectApplyThis = false;
35 | }
36 | }
37 |
38 | public override void ApplyPatch()
39 | {
40 | base.ApplyPatch();
41 | var genericTranslation = Expression as GenericNameTranslation;
42 | if (genericTranslation != null)
43 | {
44 | var identifier = Name as IdentifierNameTranslation;
45 | if (identifier != null && identifier.IsStatic)
46 | {
47 | genericTranslation.ExcludeTypeParameter = true;
48 | if (IsInInvocation)
49 | {
50 | identifier.TypeArgumentList = genericTranslation.TypeArgumentList;
51 | }
52 |
53 | }
54 | }
55 | }
56 |
57 | protected override string InnerTranslate()
58 | {
59 |
60 | string str = Syntax.ToString();
61 |
62 | return NormalTranslate();
63 | }
64 |
65 | private string NormalTranslate()
66 | {
67 | return string.Format("{0}{1}{2}", Expression.Translate(), Syntax.OperatorToken.ToString(), Name.Translate());
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/ConstructorDeclarationTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class ConstructorDeclarationTranslation : BaseMethodDeclarationTranslation
12 | {
13 | public new ConstructorDeclarationSyntax Syntax
14 | {
15 | get { return (ConstructorDeclarationSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public ConstructorInitializerTranslation Initializer { get; set; }
20 |
21 | public ConstructorDeclarationTranslation() { }
22 |
23 | public bool IsDeclarationOverload { get; set; }
24 | public ConstructorDeclarationTranslation(ConstructorDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
25 | {
26 | Identifier = syntax.Identifier.Get(this);
27 |
28 | if (syntax.Initializer != null)
29 | {
30 | Initializer = syntax.Initializer.Get(this);
31 | }
32 | }
33 |
34 | public override void ApplyPatch()
35 | {
36 | base.ApplyPatch();
37 | var identifier = Identifier.SyntaxString;
38 | if (identifier == ".ctor")
39 | {
40 | Identifier.SyntaxString = "constructor";
41 | }
42 | }
43 |
44 | protected override string InnerTranslate()
45 | {
46 | // var identifier = Identifier.SyntaxString;
47 |
48 | var identifier = "constructor";
49 | // TypeScript constructor does not have modifiers
50 | if (SemicolonToken == null || SemicolonToken.IsEmpty)
51 | {
52 | string baseCall = string.Empty;
53 | if(Initializer!=null)
54 | {
55 | return $@" {identifier} {ParameterList.Translate()}
56 | {{
57 | {Initializer.Translate()}
58 | {Body.Statements.Translate()}
59 | }} ";
60 | }
61 | return $@" {identifier} {ParameterList.Translate()}
62 | {Body.Translate()}";
63 | }
64 |
65 | return $" {identifier} {ParameterList.Translate()}; ";
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste/Translation/UsingStatementTranslation.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.CodeAnalysis;
2 | using Microsoft.CodeAnalysis.CSharp.Syntax;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace RoslynTypeScript.Translation
10 | {
11 | public class UsingStatementTranslation : StatementTranslation
12 | {
13 | public new UsingStatementSyntax Syntax
14 | {
15 | get { return (UsingStatementSyntax)base.Syntax; }
16 | set { base.Syntax = value; }
17 | }
18 |
19 | public UsingStatementTranslation() { }
20 | public UsingStatementTranslation(UsingStatementSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
21 | {
22 | Declaration = syntax.Declaration.Get(this);
23 | Expression = syntax.Expression.Get(this);
24 | Statement = syntax.Statement.Get(this);
25 |
26 | //if(Expression != null)
27 | //{
28 | // throw new Exception("only support Declaration");
29 | //}
30 | }
31 |
32 | public VariableDeclarationTranslation Declaration { get; set; }
33 | public ExpressionTranslation Expression { get; set; }
34 | public StatementTranslation Statement { get; set; }
35 |
36 |
37 | protected override string InnerTranslate()
38 | {
39 | // support first variable only
40 | //if(Declaration.Variables.SyntaxCollection.Count!=1)
41 | //{
42 | // throw new Exception("only support one variable");
43 | //}
44 |
45 | string variable = Declaration?.Variables.GetEnumerable().First().Identifier.ToString() ?? "__temp";
46 | string block = Statement.Translate();
47 | if(!(Statement is BlockTranslation))
48 | {
49 | block = $@"{{
50 | {block}
51 | }}";
52 | }
53 | string callDisposable = $"if({variable}!=null) {variable}.Dispose();";
54 | string declaration = Declaration?.Translate() ?? $"var {variable} = {Expression.Translate()}";
55 | return $@"{declaration}
56 | try
57 | {block}
58 | finally {{
59 | {callDisposable}
60 | }}";
61 |
62 |
63 | //return Syntax.ToString();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Console/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using TypescriptSyntaxPaste.VSIX;
7 |
8 | namespace TypescriptSyntaxPaste.Console
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | var cScript = @"class Foo{}";
15 | CSharpToTypescriptConverter csharpToTypescriptConverter = new CSharpToTypescriptConverter();
16 | var typescript = csharpToTypescriptConverter.ConvertToTypescript(cScript, new MySettingStore());
17 |
18 | System.Console.WriteLine(typescript);
19 | }
20 | }
21 |
22 |
23 | class MySettingStore : ISettingStore
24 | {
25 | public bool AddIPrefixInterfaceDeclaration
26 | {
27 | get
28 | {
29 | return true;
30 | }
31 |
32 | set
33 | {
34 | throw new NotImplementedException();
35 | }
36 | }
37 |
38 | public bool IsConvertListToArray
39 | {
40 | get
41 | {
42 | return true;
43 | }
44 |
45 | set
46 | {
47 | throw new NotImplementedException();
48 | }
49 | }
50 |
51 | public bool IsConvertMemberToCamelCase
52 | {
53 | get
54 | {
55 | return false;
56 | }
57 |
58 | set
59 | {
60 | throw new NotImplementedException();
61 | }
62 | }
63 |
64 | public bool IsConvertToInterface
65 | {
66 | get
67 | {
68 | return true;
69 | }
70 |
71 | set
72 | {
73 | throw new NotImplementedException();
74 | }
75 | }
76 |
77 | public bool IsInterfaceOptionalProperties
78 | {
79 | get
80 | {
81 | return false;
82 | }
83 |
84 | set
85 | {
86 | throw new NotImplementedException();
87 | }
88 | }
89 |
90 | public TypeNameReplacementData[] ReplacedTypeNameArray
91 | {
92 | get
93 | {
94 | return new TypeNameReplacementData[0];
95 | }
96 |
97 | set
98 | {
99 | throw new NotImplementedException();
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/TypescriptSyntaxPaste.Tests/ThrowStatementTests.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 TypescriptSyntaxPaste.Tests
9 | {
10 | [TestClass]
11 | public class ThrowStatementTests
12 | {
13 | [TestMethod]
14 | public void Convert_Without_CatchClauseDeclarationAndThrowVariable()
15 | {
16 | ConvertHelper.AssertConvertingIgnoreSpaces(@"public void Foo2()
17 | {
18 | try
19 | { }
20 | catch
21 | {
22 | throw;
23 | }
24 | }", @"public Foo2(): void {
25 | try {
26 |
27 | }
28 | catch (err) {
29 | throw err;
30 | }
31 |
32 | }");
33 | }
34 |
35 | [TestMethod]
36 | public void Convert_Without_CatchClauseVariableAndThrowVariable()
37 | {
38 | ConvertHelper.AssertConvertingIgnoreSpaces(@"
39 | public void Foo1()
40 | {
41 | try
42 | { }
43 | catch (Exception)
44 | {
45 | throw;
46 | }
47 | }
48 | ",
49 | @"
50 | public Foo1(): void {
51 | try {
52 |
53 | }
54 | catch (err) {
55 | throw err;
56 | }
57 |
58 | }
59 | ");
60 | }
61 |
62 | [TestMethod]
63 | public void Convert_WithCatchVariableAndNoThrowVariable()
64 | {
65 | ConvertHelper.AssertConvertingIgnoreSpaces(@"
66 | public void Foo3()
67 | {
68 | try
69 | { }
70 | catch(Exception ett)
71 | {
72 | throw;
73 | }
74 | }
75 | ",
76 | @"
77 | public Foo3(): void {
78 | try {
79 |
80 | }
81 | catch (ett) {
82 | throw ett;
83 | }
84 |
85 | }
86 | ");
87 | }
88 |
89 | [TestMethod]
90 | public void Convert_WithCatchAndThrowVariable()
91 | {
92 | ConvertHelper.AssertConvertingIgnoreSpaces(@"
93 | public void Foo4()
94 | {
95 | try
96 | { }
97 | catch (Exception ett)
98 | {
99 | throw ett;
100 | }
101 | }
102 | ",
103 | @"
104 | public Foo4(): void {
105 | try {
106 |
107 | }
108 | catch (ett) {
109 | throw ett;
110 | }
111 |
112 | }
113 | ");
114 | }
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------