Skip to content

Commit 0750eb3

Browse files
authored
Merge pull request #43 from canhorn/bug/fix_constructor_no_namespace_generation
Fixed No Namespace issue found in Accessors, Methods, Properties and constructors.
2 parents 530ae25 + b95482a commit 0750eb3

File tree

19 files changed

+317
-11
lines changed

19 files changed

+317
-11
lines changed

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
)[[BASE_CLASS_CALL]]
44
{
55
var entity = EventHorizonBlazorInterop.New(
6-
new string[] { [[PROPERTY_NAMESPACE]], "[[CLASS_NAME]]" },
6+
new string[] { [[PROPERTY_NAMESPACE]]"[[CLASS_NAME]]" },
77
[[PROPERTY_ARGUMENTS]]
88
);
99
___guid = entity.___guid;

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/AccessorsSectionWriter.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ClassGenerationTemplates templates
4646
var entityNamespace = string.Join(
4747
", ",
4848
namespaceParts.Select(part => @$"""{part}""")
49-
);
49+
) + ", ";
5050
var property = accessor.Name;
5151
var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate;
5252
var cacheSection = string.Empty;
@@ -57,6 +57,11 @@ ClassGenerationTemplates templates
5757
template = templates.AccessorWithSetter;
5858
}
5959

60+
if (entityNamespace == @""""", ")
61+
{
62+
entityNamespace = string.Empty;
63+
}
64+
6065
if (accessor.IsStatic)
6166
{
6267
root = $"\"{namespaceParts.FirstOrDefault()}\"";
@@ -73,10 +78,15 @@ ClassGenerationTemplates templates
7378
else
7479
{
7580
property = $"{classStatement.Name}.{accessor.Name}";
81+
if (entityNamespace == string.Empty)
82+
{
83+
root = $"\"{classStatement.Name}\"";
84+
property = accessor.Name;
85+
}
7686
}
7787
}
7888

79-
if(isEnum)
89+
if (isEnum)
8090
{
8191
propertyGetterResultType = templates.InteropGet;
8292
}

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/ConstructorSectionWriter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ ClassGenerationTemplates templates
5454
classStatement.Namespace
5555
.Split(".")
5656
.Select(part => @$"""{part}""")
57-
);
57+
) + ", ";
58+
59+
if (entityNamespace == @""""", ")
60+
{
61+
entityNamespace = string.Empty;
62+
}
5863

5964
return template.Replace(
6065
"[[CLASS_NAME]]",

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/MethodsSectionWriter.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ ClassGenerationTemplates templates
6060
var returnTypeContent = templates.InteropFunc;
6161
var arguments = string.Empty;
6262
var argumentStrings = new List<string>();
63+
var classNamespace = classStatement.Namespace;
6364
var namespacedMethod = string.Join(
6465
".",
65-
classStatement.Namespace,
66+
classNamespace,
6667
classStatement.Name,
6768
method.Name
6869
);
@@ -78,6 +79,15 @@ ClassGenerationTemplates templates
7879
var taskAsync = string.Empty;
7980
var taskAwait = string.Empty;
8081

82+
if (classNamespace == string.Empty)
83+
{
84+
namespacedMethod = string.Join(
85+
".",
86+
classStatement.Name,
87+
method.Name
88+
);
89+
}
90+
8191
// Argument Generation
8292
if (isAction)
8393
{
@@ -223,12 +233,22 @@ ClassGenerationTemplates templates
223233

224234
if (method.IsStatic)
225235
{
236+
var classStatementIdentitiferList = new string[] {
237+
classStatement.Name,
238+
};
239+
if (classNamespace != string.Empty)
240+
{
241+
classStatementIdentitiferList = new string[]
242+
{
243+
classStatement.Namespace,
244+
classStatement.Name,
245+
};
246+
}
226247
propertyIdentifier = string.Join(
227248
", ",
228249
string.Join(
229250
".",
230-
classStatement.Namespace,
231-
classStatement.Name
251+
classStatementIdentitiferList
232252
).Split(".").Select(part => @$"""{part}""")
233253
);
234254
}

Source/EventHorizon.Blazor.TypeScript.Interop.Generator/Writers/PropertiesSectionWriter.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ClassGenerationTemplates templates
5252
var entityNamespace = string.Join(
5353
", ",
5454
namespaceParts.Select(part => @$"""{part}""")
55-
);
55+
) + ", ";
5656
var propertyIdentifier = property.Name;
5757
var propertyGetterTemplate = templates.ReturnTypePrimitiveTemplate;
5858
var cacheSection = string.Empty;
@@ -63,6 +63,11 @@ ClassGenerationTemplates templates
6363
template = templates.Accessor;
6464
}
6565

66+
if (entityNamespace == @""""", ")
67+
{
68+
entityNamespace = string.Empty;
69+
}
70+
6671
if (property.IsStatic)
6772
{
6873

@@ -80,6 +85,11 @@ ClassGenerationTemplates templates
8085
else
8186
{
8287
propertyIdentifier = $"{classStatement.Name}.{property.Name}";
88+
if (entityNamespace == string.Empty)
89+
{
90+
root = $"\"{classStatement.Name}\"";
91+
propertyIdentifier = property.Name;
92+
}
8393
}
8494
}
8595

Source/Server/EventHorizon.Blazor.Interop.Generator/Templates/ConstructorWithArgumentsTemplate.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
)
44
{
55
var entity = await EventHorizonBlazorInterop.New(
6-
new string[] { [[PROPERTY_NAMESPACE]], "[[CLASS_NAME]]" },
6+
new string[] { [[PROPERTY_NAMESPACE]]"[[CLASS_NAME]]" },
77
[[PROPERTY_ARGUMENTS]]
88
);
99

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/Formatter/ExpectedResults/CSharpTextFormatter.Expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class CSharpTextClass : CachedEntityObject
108108

109109
public CSharpTextClass(object target = null)
110110
{
111-
var entity = EventHorizonBlazorInterop.New(new string[]{"", "CSharpTextClass"}, target);
111+
var entity = EventHorizonBlazorInterop.New(new string[]{"CSharpTextClass"}, target);
112112
___guid = entity.___guid;
113113
}
114114

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/// Generated - Do Not Edit
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text.Json.Serialization;
5+
using System.Threading.Tasks;
6+
using EventHorizon.Blazor.Interop;
7+
using EventHorizon.Blazor.Interop.Callbacks;
8+
using Microsoft.JSInterop;
9+
10+
11+
12+
[JsonConverter(typeof(CachedEntityConverter<ExampleClass>))]
13+
public class ExampleClass : CachedEntityObject
14+
{
15+
#region Static Accessors
16+
17+
public static decimal Now
18+
{
19+
get
20+
{
21+
return EventHorizonBlazorInterop.Get<decimal>(
22+
"ExampleClass",
23+
"Now"
24+
);
25+
}
26+
}
27+
#endregion
28+
29+
#region Static Properties
30+
31+
#endregion
32+
33+
#region Static Methods
34+
35+
#endregion
36+
37+
#region Accessors
38+
39+
#endregion
40+
41+
#region Properties
42+
43+
#endregion
44+
45+
#region Constructor
46+
public ExampleClass() : base() { }
47+
48+
public ExampleClass(
49+
ICachedEntity entity
50+
) : base(entity)
51+
{
52+
___guid = entity.___guid;
53+
}
54+
55+
56+
#endregion
57+
58+
#region Methods
59+
60+
#endregion
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export class ExampleClass {
2+
static get Now(): number;
3+
}

Tests/EventHorizon.Blazor.TypeScript.Interop.Generator.Tests/GenerateClassStatementStringTests/AccessorsGenerationTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ ASTParserType parserType
5555
[InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.Sdcb)]
5656
[InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.Sdcb)]
5757
[InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.Sdcb)]
58+
[InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.Sdcb)]
5859
[InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.Sdcb)]
5960
public void ShouldGenerateAccessorScenarioStringsWithSdcb(
6061
string sourceFile,
@@ -117,6 +118,7 @@ ASTParserType parserType
117118
[InlineData("InterfaceResponse.ts", "Accessors", "Scenarios", "InterfaceResponse.Expected.txt", ASTParserType.NodeJS)]
118119
[InlineData("NamespacedTyping.ts", "Accessors", "Scenarios", "NamespacedTyping.Expected.txt", ASTParserType.NodeJS)]
119120
[InlineData("NullableTyping.ts", "Accessors", "Scenarios", "NullableTyping.Expected.txt", ASTParserType.NodeJS)]
121+
[InlineData("StaticNoNamespace.d.ts", "Accessors", "Scenarios", "StaticNoNamespace.d.Expected.txt", ASTParserType.NodeJS)]
120122
[InlineData("StaticRootNamespace.ts", "Accessors", "Scenarios", "StaticRootNamespace.Expected.txt", ASTParserType.NodeJS)]
121123
public void ShouldGenerateAccessorScenarioStringsWithNodeJS(
122124
string sourceFile,

0 commit comments

Comments
 (0)