From 894823a9c6bd9bdef5d5fdb9a4a28ed7a34be65b Mon Sep 17 00:00:00 2001 From: Cody Merritt Anhorn Date: Thu, 22 Apr 2021 08:37:01 -0500 Subject: [PATCH 1/2] Backup work --- .../AstParser/NodeImpl/NodeJS_ASTWrapper.cs | 22 +++---- .../ConstructorWithArgumentsTemplate.txt | 2 +- .../Writers/AccessorsSectionWriter.cs | 7 ++- .../Writers/ConstructorSectionWriter.cs | 5 ++ .../Writers/PropertiesSectionWriter.cs | 5 ++ .../ConstructorWithArgumentsTemplate.txt | 2 +- .../Scenarios/NoNamespace.d.Expected.txt | 59 ++++++++++++++++++ .../Accessors/Scenarios/NoNamespace.d.ts | 3 + .../NoNamespaceWithArguments.Expected.txt | 60 +++++++++++++++++++ .../Constructors/NoNamespaceWithArguments.ts | 3 + .../StringGenerationTests.cs | 4 +- 11 files changed, 157 insertions(+), 15 deletions(-) create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs index 584160f4..e7739376 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs @@ -60,17 +60,17 @@ string source ).GetAwaiter().GetResult(); // Use for testing the generated AST - //File.WriteAllText( - // Path.Combine( - // ".", - // "AstParser", - // "NodeImpl", - // "NodeJS", - // "_generated", - // "ast.json" - // ), - // result - //); + File.WriteAllText( + Path.Combine( + ".", + "AstParser", + "NodeImpl", + "NodeJS", + "_generated", + "ast.json" + ), + result + ); var ast = JsonSerializer.Deserialize( result, new JsonSerializerOptions diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt index fa4d1073..09cb601e 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt @@ -3,7 +3,7 @@ )[[BASE_CLASS_CALL]] { var entity = EventHorizonBlazorInterop.New( - new string[] { [[PROPERTY_NAMESPACE]], "[[CLASS_NAME]]" }, + new string[] { [[PROPERTY_NAMESPACE]]"[[CLASS_NAME]]" }, [[PROPERTY_ARGUMENTS]] ); ___guid = entity.___guid; diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs index 27ce6aca..7a144174 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs @@ -76,7 +76,7 @@ ClassGenerationTemplates templates } } - if(isEnum) + if (isEnum) { propertyGetterResultType = templates.InteropGet; } @@ -96,6 +96,11 @@ ClassGenerationTemplates templates propertyGetterResultType = templates.InteropGetArray; } + if (entityNamespace == @"""") + { + entityNamespace = string.Empty; + } + template = template .Replace( "[[PROPERTY_GETTER]]", diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs index cf749d95..9093d254 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs @@ -56,6 +56,11 @@ ClassGenerationTemplates templates .Select(part => @$"""{part}""") ); + if (entityNamespace == @"""""") + { + entityNamespace = string.Empty; + } + return template.Replace( "[[CLASS_NAME]]", classStatement.Name diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs index 2e8be8b3..8ebc8233 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs @@ -116,6 +116,11 @@ ClassGenerationTemplates templates template = "// [[NAME]] is not supported by the platform yet"; } + if (entityNamespace == @"""") + { + entityNamespace = string.Empty; + } + template = template .Replace( "[[PROPERTY_GETTER]]", diff --git a/Source/Server/EventHorizon.Blazor.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt b/Source/Server/EventHorizon.Blazor.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt index bbcec4ce..ec227370 100644 --- a/Source/Server/EventHorizon.Blazor.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt +++ b/Source/Server/EventHorizon.Blazor.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt @@ -3,7 +3,7 @@ ) { var entity = await EventHorizonBlazorInterop.New( - new string[] { [[PROPERTY_NAMESPACE]], "[[CLASS_NAME]]" }, + new string[] { [[PROPERTY_NAMESPACE]]"[[CLASS_NAME]]" }, [[PROPERTY_ARGUMENTS]] ); diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt new file mode 100644 index 00000000..52dff68a --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt @@ -0,0 +1,59 @@ +/// Generated - Do Not Edit +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using EventHorizon.Blazor.Interop; +using EventHorizon.Blazor.Interop.Callbacks; +using Microsoft.JSInterop; + + + +[JsonConverter(typeof(CachedEntityConverter))] +public class ExampleClass : CachedEntityObject +{ + #region Static Accessors + + public static decimal Now + { + get + { + return EventHorizonBlazorInterop.Get( + "ExampleClass", + "Now" + ); + } + } + #endregion + + #region Static Properties + + #endregion + + #region Static Methods + + #endregion + + #region Accessors + + #endregion + + #region Properties + + #endregion + + #region Constructor + public ExampleClass() : base() { } + + public ExampleClass( + ICachedEntity entity + ) : base(entity) + { + ___guid = entity.___guid; + } + #endregion + + #region Methods + + #endregion +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts new file mode 100644 index 00000000..9c78f5e6 --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts @@ -0,0 +1,3 @@ +export class ExampleClass { + static get Now(): number; +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt new file mode 100644 index 00000000..ada606bd --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt @@ -0,0 +1,60 @@ +/// Generated - Do Not Edit +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using EventHorizon.Blazor.Interop; +using EventHorizon.Blazor.Interop.Callbacks; +using Microsoft.JSInterop; + + + +[JsonConverter(typeof(CachedEntityConverter))] +public class ExampleClass : CachedEntityObject +{ + #region Static Accessors + + #endregion + + #region Static Properties + + #endregion + + #region Static Methods + + #endregion + + #region Accessors + + #endregion + + #region Properties + + #endregion + + #region Constructor + public ExampleClass() : base() { } + + public ExampleClass( + ICachedEntity entity + ) : base(entity) + { + ___guid = entity.___guid; + } + + public ExampleClass( + string arg1 + ) + { + var entity = EventHorizonBlazorInterop.New( + new string[] { "ExampleClass" }, + arg1 + ); + ___guid = entity.___guid; + } + #endregion + + #region Methods + + #endregion +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts new file mode 100644 index 00000000..447662fc --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts @@ -0,0 +1,3 @@ +export class ExampleClass { + constructor(arg1: string) { } +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs index dc37a558..459f3ec9 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs @@ -12,6 +12,7 @@ public class StringGenerationTests : GenerateStringTestBase [InlineData("DotNetNormalizedArguments.ts", "Constructors", "DotNetNormalizedArguments.Expected.txt", ASTParserType.Sdcb)] [InlineData("MixedArguments.ts", "Constructors", "MixedArguments.Expected.txt", ASTParserType.Sdcb)] [InlineData("NoConstructor.ts", "Constructors", "NoConstructor.Expected.txt", ASTParserType.Sdcb)] + [InlineData("NoNamespaceWithArguments.ts", "Constructors", "NoNamespaceWithArguments.Expected.txt", ASTParserType.Sdcb)] [InlineData("WithActionArgument.ts", "Constructors", "WithActionArgument.Expected.txt", ASTParserType.Sdcb)] [InlineData("WithActionGenericArgument.ts", "Constructors", "WithActionGenericArgument.Expected.txt", ASTParserType.Sdcb)] [InlineData("WithNullArguments.ts", "Constructors", "WithNullArguments.Expected.txt", ASTParserType.Sdcb)] @@ -106,10 +107,11 @@ ASTParserType parserType [InlineData("DotNetNormalizedArguments.ts", "Constructors", "DotNetNormalizedArguments.Expected.txt", ASTParserType.NodeJS)] [InlineData("MixedArguments.ts", "Constructors", "MixedArguments.Expected.txt", ASTParserType.NodeJS)] [InlineData("NoConstructor.ts", "Constructors", "NoConstructor.Expected.txt", ASTParserType.NodeJS)] + [InlineData("NoNamespaceWithArguments.ts", "Constructors", "NoNamespaceWithArguments.Expected.txt", ASTParserType.NodeJS)] [InlineData("WithActionArgument.ts", "Constructors", "WithActionArgument.Expected.txt", ASTParserType.NodeJS)] [InlineData("WithActionGenericArgument.ts", "Constructors", "WithActionGenericArgument.Expected.txt", ASTParserType.NodeJS)] [InlineData("WithNullArguments.ts", "Constructors", "WithNullArguments.Expected.txt", ASTParserType.NodeJS)] - public void ShouldGenerateConstructorStringsUsingNodeJS( + public void ShouldGenerateConstructorStringsUsingNodeJS( string sourceFile, string path, string expectedFile, From b95482a103554e923c135ddfee0349a84284c3ab Mon Sep 17 00:00:00 2001 From: Cody Merritt Anhorn Date: Thu, 22 Apr 2021 10:32:39 -0500 Subject: [PATCH 2/2] Fixed No Namespace issue found in Accessors, Methods, Properties and constructors. --- .../AstParser/NodeImpl/NodeJS_ASTWrapper.cs | 22 +++---- .../Writers/AccessorsSectionWriter.cs | 17 ++++-- .../Writers/ConstructorSectionWriter.cs | 4 +- .../Writers/MethodsSectionWriter.cs | 26 +++++++- .../Writers/PropertiesSectionWriter.cs | 17 ++++-- .../CSharpTextFormatter.Expected.txt | 2 +- ...d.txt => StaticNoNamespace.d.Expected.txt} | 2 + ...oNamespace.d.ts => StaticNoNamespace.d.ts} | 0 .../AccessorsGenerationTests.cs | 2 + ...> NoNamespaceWithArguments.d.Expected.txt} | 0 .../NoNamespaceWithArguments.d.ts | 3 + .../Constructors/NoNamespaceWithArguments.ts | 3 - .../MethodScenarioTests.cs | 2 + .../StaticNoNamespace.d.Expected.txt | 59 ++++++++++++++++++ .../Methods/Scenarios/StaticNoNamespace.d.ts | 3 + .../StaticNoNamespace.d.Expected.txt | 61 +++++++++++++++++++ .../Scenarios/StaticNoNamespace.d.ts | 3 + .../PropertyGenerationTests.cs | 2 + .../StringGenerationTests.cs | 4 +- 19 files changed, 198 insertions(+), 34 deletions(-) rename Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/{NoNamespace.d.Expected.txt => StaticNoNamespace.d.Expected.txt} (99%) rename Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/{NoNamespace.d.ts => StaticNoNamespace.d.ts} (100%) rename Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/{NoNamespaceWithArguments.Expected.txt => NoNamespaceWithArguments.d.Expected.txt} (100%) create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.ts delete mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.Expected.txt create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.ts create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.Expected.txt create mode 100644 Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.ts diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs index e7739376..584160f4 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/AstParser/NodeImpl/NodeJS_ASTWrapper.cs @@ -60,17 +60,17 @@ string source ).GetAwaiter().GetResult(); // Use for testing the generated AST - File.WriteAllText( - Path.Combine( - ".", - "AstParser", - "NodeImpl", - "NodeJS", - "_generated", - "ast.json" - ), - result - ); + //File.WriteAllText( + // Path.Combine( + // ".", + // "AstParser", + // "NodeImpl", + // "NodeJS", + // "_generated", + // "ast.json" + // ), + // result + //); var ast = JsonSerializer.Deserialize( result, new JsonSerializerOptions diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs index 7a144174..e8b9a729 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs @@ -46,7 +46,7 @@ ClassGenerationTemplates templates var entityNamespace = string.Join( ", ", namespaceParts.Select(part => @$"""{part}""") - ); + ) + ", "; var property = accessor.Name; var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate; var cacheSection = string.Empty; @@ -57,6 +57,11 @@ ClassGenerationTemplates templates template = templates.AccessorWithSetter; } + if (entityNamespace == @""""", ") + { + entityNamespace = string.Empty; + } + if (accessor.IsStatic) { root = $"\"{namespaceParts.FirstOrDefault()}\""; @@ -73,6 +78,11 @@ ClassGenerationTemplates templates else { property = $"{classStatement.Name}.{accessor.Name}"; + if (entityNamespace == string.Empty) + { + root = $"\"{classStatement.Name}\""; + property = accessor.Name; + } } } @@ -96,11 +106,6 @@ ClassGenerationTemplates templates propertyGetterResultType = templates.InteropGetArray; } - if (entityNamespace == @"""") - { - entityNamespace = string.Empty; - } - template = template .Replace( "[[PROPERTY_GETTER]]", diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs index 9093d254..6956ff2c 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs @@ -54,9 +54,9 @@ ClassGenerationTemplates templates classStatement.Namespace .Split(".") .Select(part => @$"""{part}""") - ); + ) + ", "; - if (entityNamespace == @"""""") + if (entityNamespace == @""""", ") { entityNamespace = string.Empty; } diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/MethodsSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/MethodsSectionWriter.cs index a230e34a..6403a0d0 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/MethodsSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/MethodsSectionWriter.cs @@ -60,9 +60,10 @@ ClassGenerationTemplates templates var returnTypeContent = templates.InteropFunc; var arguments = string.Empty; var argumentStrings = new List(); + var classNamespace = classStatement.Namespace; var namespacedMethod = string.Join( ".", - classStatement.Namespace, + classNamespace, classStatement.Name, method.Name ); @@ -78,6 +79,15 @@ ClassGenerationTemplates templates var taskAsync = string.Empty; var taskAwait = string.Empty; + if (classNamespace == string.Empty) + { + namespacedMethod = string.Join( + ".", + classStatement.Name, + method.Name + ); + } + // Argument Generation if (isAction) { @@ -223,12 +233,22 @@ ClassGenerationTemplates templates if (method.IsStatic) { + var classStatementIdentitiferList = new string[] { + classStatement.Name, + }; + if (classNamespace != string.Empty) + { + classStatementIdentitiferList = new string[] + { + classStatement.Namespace, + classStatement.Name, + }; + } propertyIdentifier = string.Join( ", ", string.Join( ".", - classStatement.Namespace, - classStatement.Name + classStatementIdentitiferList ).Split(".").Select(part => @$"""{part}""") ); } diff --git a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs index 8ebc8233..65c56234 100644 --- a/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs +++ b/Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs @@ -52,7 +52,7 @@ ClassGenerationTemplates templates var entityNamespace = string.Join( ", ", namespaceParts.Select(part => @$"""{part}""") - ); + ) + ", "; var propertyIdentifier = property.Name; var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate; var cacheSection = string.Empty; @@ -63,6 +63,11 @@ ClassGenerationTemplates templates template = templates.Accessor; } + if (entityNamespace == @""""", ") + { + entityNamespace = string.Empty; + } + if (property.IsStatic) { @@ -80,6 +85,11 @@ ClassGenerationTemplates templates else { propertyIdentifier = $"{classStatement.Name}.{property.Name}"; + if (entityNamespace == string.Empty) + { + root = $"\"{classStatement.Name}\""; + propertyIdentifier = property.Name; + } } } @@ -116,11 +126,6 @@ ClassGenerationTemplates templates template = "// [[NAME]] is not supported by the platform yet"; } - if (entityNamespace == @"""") - { - entityNamespace = string.Empty; - } - template = template .Replace( "[[PROPERTY_GETTER]]", diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt index 27793410..13f81863 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt @@ -108,7 +108,7 @@ public class CSharpTextClass : CachedEntityObject public CSharpTextClass(object target = null) { - var entity = EventHorizonBlazorInterop.New(new string[]{"", "CSharpTextClass"}, target); + var entity = EventHorizonBlazorInterop.New(new string[]{"CSharpTextClass"}, target); ___guid = entity.___guid; } diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.Expected.txt similarity index 99% rename from Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt rename to Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.Expected.txt index 52dff68a..1da0c487 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.Expected.txt +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.Expected.txt @@ -51,6 +51,8 @@ public class ExampleClass : CachedEntityObject { ___guid = entity.___guid; } + + #endregion #region Methods diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.ts similarity index 100% rename from Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/NoNamespace.d.ts rename to Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Accessors/Scenarios/StaticNoNamespace.d.ts diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/AccessorsGenerationTests.cs b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/AccessorsGenerationTests.cs index 3a27931a..8dd7ed07 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/AccessorsGenerationTests.cs +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/AccessorsGenerationTests.cs @@ -55,6 +55,7 @@ ASTParserType parserType [InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.Sdcb)] [InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.Sdcb)] [InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.Sdcb)] + [InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)] [InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.Sdcb)] public void ShouldGenerateAccessorScenarioStringsWithSdcb( string sourceFile, @@ -117,6 +118,7 @@ ASTParserType parserType [InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.NodeJS)] [InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.NodeJS)] [InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.NodeJS)] + [InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)] [InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.NodeJS)] public void ShouldGenerateAccessorScenarioStringsWithNodeJS( string sourceFile, diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.Expected.txt similarity index 100% rename from Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.Expected.txt rename to Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.Expected.txt diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.ts new file mode 100644 index 00000000..d42eefd1 --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.d.ts @@ -0,0 +1,3 @@ +export class ExampleClass { + constructor(arg1: string); +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts deleted file mode 100644 index 447662fc..00000000 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Constructors/NoNamespaceWithArguments.ts +++ /dev/null @@ -1,3 +0,0 @@ -export class ExampleClass { - constructor(arg1: string) { } -} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/MethodScenarioTests.cs b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/MethodScenarioTests.cs index 3332d347..010b99c6 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/MethodScenarioTests.cs +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/MethodScenarioTests.cs @@ -35,6 +35,7 @@ ASTParserType parserType [InlineData("MethodStaticClassWithNullArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithNullArgument.Expected.txt", ASTParserType.Sdcb)] [InlineData("MethodStaticClassWithUndefinedArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithUndefinedArgument.Expected.txt", ASTParserType.Sdcb)] [InlineData("MethodStaticWithLiteralAsResult.ts", "Methods", "Scenarios", "MethodStaticWithLiteralAsResult.Expected.txt", ASTParserType.Sdcb)] + [InlineData("StaticNoNamespace.d.ts", "Methods", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)] public void ShouldGenerateStaticMethodScenarioStringsUsingSdcb( string sourceFile, string rootPath, @@ -126,6 +127,7 @@ ASTParserType parserType [InlineData("MethodStaticClassWithNullArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithNullArgument.Expected.txt", ASTParserType.NodeJS)] [InlineData("MethodStaticClassWithUndefinedArgument.ts", "Methods", "Scenarios", "MethodStaticClassWithUndefinedArgument.Expected.txt", ASTParserType.NodeJS)] [InlineData("MethodStaticWithLiteralAsResult.ts", "Methods", "Scenarios", "MethodStaticWithLiteralAsResult.Expected.txt", ASTParserType.NodeJS)] + [InlineData("StaticNoNamespace.d.ts", "Methods", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)] public void ShouldGenerateStaticMethodScenarioStringsUsingNodeJS( string sourceFile, string rootPath, diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.Expected.txt new file mode 100644 index 00000000..32f55011 --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.Expected.txt @@ -0,0 +1,59 @@ +/// Generated - Do Not Edit +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using EventHorizon.Blazor.Interop; +using EventHorizon.Blazor.Interop.Callbacks; +using Microsoft.JSInterop; + + + +[JsonConverter(typeof(CachedEntityConverter))] +public class ExampleClass : CachedEntityObject +{ + #region Static Accessors + + #endregion + + #region Static Properties + + #endregion + + #region Static Methods + public static decimal numberMethod() + { + return EventHorizonBlazorInterop.Func( + new object[] + { + new string[] { "ExampleClass", "numberMethod" } + } + ); + } + #endregion + + #region Accessors + + #endregion + + #region Properties + + #endregion + + #region Constructor + public ExampleClass() : base() { } + + public ExampleClass( + ICachedEntity entity + ) : base(entity) + { + ___guid = entity.___guid; + } + + + #endregion + + #region Methods + + #endregion +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.ts new file mode 100644 index 00000000..7e2fcfeb --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Methods/Scenarios/StaticNoNamespace.d.ts @@ -0,0 +1,3 @@ +export class ExampleClass { + static numberMethod(): number; +} \ No newline at end of file diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.Expected.txt b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.Expected.txt new file mode 100644 index 00000000..b270ea05 --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.Expected.txt @@ -0,0 +1,61 @@ +/// Generated - Do Not Edit +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using EventHorizon.Blazor.Interop; +using EventHorizon.Blazor.Interop.Callbacks; +using Microsoft.JSInterop; + + + +[JsonConverter(typeof(CachedEntityConverter))] +public class ExampleClass : CachedEntityObject +{ + #region Static Accessors + + #endregion + + #region Static Properties + + public static decimal NoneLogLevel + { + get + { + return EventHorizonBlazorInterop.Get( + "ExampleClass", + "NoneLogLevel" + ); + } + } + #endregion + + #region Static Methods + + #endregion + + #region Accessors + + #endregion + + #region Properties + + #endregion + + #region Constructor + public ExampleClass() : base() { } + + public ExampleClass( + ICachedEntity entity + ) : base(entity) + { + ___guid = entity.___guid; + } + + + #endregion + + #region Methods + + #endregion +} diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.ts b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.ts new file mode 100644 index 00000000..6cfe48a7 --- /dev/null +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/Properties/Scenarios/StaticNoNamespace.d.ts @@ -0,0 +1,3 @@ +export class ExampleClass { + static readonly NoneLogLevel: number; +} \ No newline at end of file diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/PropertyGenerationTests.cs b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/PropertyGenerationTests.cs index c427ac22..00530fc3 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/PropertyGenerationTests.cs +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/PropertyGenerationTests.cs @@ -55,6 +55,7 @@ ASTParserType parserType [InlineData("PropertyJavaScriptTypes.ts", "Properties", "Scenarios", "PropertyJavaScriptTypes.Expected.txt", ASTParserType.Sdcb)] [InlineData("PropertyParenthesized.ts", "Properties", "Scenarios", "PropertyParenthesized.Expected.txt", ASTParserType.Sdcb)] [InlineData("PropertyStaticRootNamespace.ts", "Properties", "Scenarios", "PropertyStaticRootNamespace.Expected.txt", ASTParserType.Sdcb)] + [InlineData("StaticNoNamespace.d.ts", "Properties", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)] [InlineData("TypeofResponse.ts", "Properties", "Scenarios", "TypeofResponse.Expected.txt", ASTParserType.Sdcb)] [InlineData("TypeofToPrimitiveResponse.ts", "Properties", "Scenarios", "TypeofToPrimitiveResponse.Expected.txt", ASTParserType.Sdcb)] [InlineData("UnionLiteralPropertyType.ts", "Properties", "Scenarios", "UnionLiteralPropertyType.Expected.txt", ASTParserType.Sdcb)] @@ -120,6 +121,7 @@ ASTParserType parserType [InlineData("PropertyJavaScriptTypes.ts", "Properties", "Scenarios", "PropertyJavaScriptTypes.Expected.txt", ASTParserType.NodeJS)] [InlineData("PropertyParenthesized.ts", "Properties", "Scenarios", "PropertyParenthesized.Expected.txt", ASTParserType.NodeJS)] [InlineData("PropertyStaticRootNamespace.ts", "Properties", "Scenarios", "PropertyStaticRootNamespace.Expected.txt", ASTParserType.NodeJS)] + [InlineData("StaticNoNamespace.d.ts", "Properties", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)] [InlineData("TypeofResponse.ts", "Properties", "Scenarios", "TypeofResponse.Expected.txt", ASTParserType.NodeJS)] [InlineData("TypeofToPrimitiveResponse.ts", "Properties", "Scenarios", "TypeofToPrimitiveResponse.Expected.txt", ASTParserType.NodeJS)] [InlineData("UnionLiteralPropertyType.ts", "Properties", "Scenarios", "UnionLiteralPropertyType.Expected.txt", ASTParserType.NodeJS)] diff --git a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs index 459f3ec9..209fac3a 100644 --- a/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs +++ b/Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/StringGenerationTests.cs @@ -12,7 +12,7 @@ public class StringGenerationTests : GenerateStringTestBase [InlineData("DotNetNormalizedArguments.ts", "Constructors", "DotNetNormalizedArguments.Expected.txt", ASTParserType.Sdcb)] [InlineData("MixedArguments.ts", "Constructors", "MixedArguments.Expected.txt", ASTParserType.Sdcb)] [InlineData("NoConstructor.ts", "Constructors", "NoConstructor.Expected.txt", ASTParserType.Sdcb)] - [InlineData("NoNamespaceWithArguments.ts", "Constructors", "NoNamespaceWithArguments.Expected.txt", ASTParserType.Sdcb)] + [InlineData("NoNamespaceWithArguments.d.ts", "Constructors", "NoNamespaceWithArguments.d.Expected.txt", ASTParserType.Sdcb)] [InlineData("WithActionArgument.ts", "Constructors", "WithActionArgument.Expected.txt", ASTParserType.Sdcb)] [InlineData("WithActionGenericArgument.ts", "Constructors", "WithActionGenericArgument.Expected.txt", ASTParserType.Sdcb)] [InlineData("WithNullArguments.ts", "Constructors", "WithNullArguments.Expected.txt", ASTParserType.Sdcb)] @@ -107,7 +107,7 @@ ASTParserType parserType [InlineData("DotNetNormalizedArguments.ts", "Constructors", "DotNetNormalizedArguments.Expected.txt", ASTParserType.NodeJS)] [InlineData("MixedArguments.ts", "Constructors", "MixedArguments.Expected.txt", ASTParserType.NodeJS)] [InlineData("NoConstructor.ts", "Constructors", "NoConstructor.Expected.txt", ASTParserType.NodeJS)] - [InlineData("NoNamespaceWithArguments.ts", "Constructors", "NoNamespaceWithArguments.Expected.txt", ASTParserType.NodeJS)] + [InlineData("NoNamespaceWithArguments.d.ts", "Constructors", "NoNamespaceWithArguments.d.Expected.txt", ASTParserType.NodeJS)] [InlineData("WithActionArgument.ts", "Constructors", "WithActionArgument.Expected.txt", ASTParserType.NodeJS)] [InlineData("WithActionGenericArgument.ts", "Constructors", "WithActionGenericArgument.Expected.txt", ASTParserType.NodeJS)] [InlineData("WithNullArguments.ts", "Constructors", "WithNullArguments.Expected.txt", ASTParserType.NodeJS)]