Skip to content

Commit 7dad50a

Browse files
committed
Updated generated csharp.
Added few expression, included anonymousType.
1 parent c49f506 commit 7dad50a

File tree

3 files changed

+122
-3
lines changed

3 files changed

+122
-3
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSharpToJavaScript.APIs.JS
8+
{
9+
public partial class CustomEvent
10+
{
11+
public CustomEvent(string type, dynamic eventInitDict) { }
12+
}
13+
}

CSharpToJavaScript/APIs/JS/Generated/JS.generated.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//07.08.2023 14:37:48
1+
//11.08.2023 14:29:24
22
using static CSharpToJavaScript.APIs.JS.GlobalObject;
33
using CSharpToJavaScript.Utils;
44
using System.Collections.Generic;
@@ -155,14 +155,16 @@ public partial class Window
155155
}
156156

157157
///<include file='Utils/Docs/CustomEvent/CustomEvent.generated.xml' path='docs/CustomEvent/*'/>
158-
[To(ToAttribute.FirstCharToLowerCase)]
158+
[To(ToAttribute.Default)]
159159
public partial class CustomEvent : Event
160160
{
161161
///<include file='Utils/Docs/CustomEventCustomEvent/CustomEventCustomEvent.generated.xml' path='docs/CustomEventCustomEvent/*'/>
162162
public CustomEvent(string type, CustomEventInit eventInitDict) { }
163163
///<include file='Utils/Docs/CustomEventDetail/CustomEventDetail.generated.xml' path='docs/CustomEventDetail/*'/>
164+
[To(ToAttribute.FirstCharToLowerCase)]
164165
public dynamic Detail { get; }
165166
///<include file='Utils/Docs/CustomEventInitCustomEvent/CustomEventInitCustomEvent.generated.xml' path='docs/CustomEventInitCustomEvent/*'/>
167+
[To(ToAttribute.FirstCharToLowerCase)]
166168
public Undefined InitCustomEvent(string type, bool bubbles, bool cancelable, dynamic detail) { throw new System.NotImplementedException(); }
167169
}
168170

CSharpToJavaScript/Walker.cs

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,17 @@ public override void VisitArgument(ArgumentSyntax node)
494494
case SyntaxKind.StringLiteralExpression:
495495
case SyntaxKind.InterpolatedStringExpression:
496496
case SyntaxKind.ObjectCreationExpression:
497-
{
497+
case SyntaxKind.ImplicitObjectCreationExpression:
498+
{
498499
Visit(asNode);
499500
break;
501+
}
502+
case SyntaxKind.AnonymousObjectCreationExpression:
503+
{
504+
VisitAnonymousObjectCreationExpression(asNode as AnonymousObjectCreationExpressionSyntax);
505+
break;
500506
}
507+
501508
case SyntaxKind.ElementAccessExpression:
502509
case SyntaxKind.IdentifierName:
503510
case SyntaxKind.SimpleMemberAccessExpression:
@@ -528,6 +535,91 @@ public override void VisitArgument(ArgumentSyntax node)
528535
}
529536
}
530537

538+
public override void VisitAnonymousObjectCreationExpression(AnonymousObjectCreationExpressionSyntax node)
539+
{
540+
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
541+
542+
for (int i = 0; i < nodesAndTokens.Count; i++)
543+
{
544+
SyntaxNode? asNode = nodesAndTokens[i].AsNode();
545+
546+
if (asNode != null)
547+
{
548+
SyntaxKind kind = asNode.Kind();
549+
550+
switch (kind)
551+
{
552+
case SyntaxKind.AnonymousObjectMemberDeclarator:
553+
Visit(asNode);
554+
break;
555+
default:
556+
SM.Log($"asNode : {kind}");
557+
break;
558+
}
559+
}
560+
else
561+
{
562+
SyntaxToken asToken = nodesAndTokens[i].AsToken();
563+
SyntaxKind kind = asToken.Kind();
564+
565+
switch (kind)
566+
{
567+
case SyntaxKind.OpenBraceToken:
568+
case SyntaxKind.CloseBraceToken:
569+
VisitToken(asToken);
570+
break;
571+
case SyntaxKind.NewKeyword:
572+
break;
573+
default:
574+
SM.Log($"asToken : {kind}");
575+
break;
576+
}
577+
}
578+
}
579+
}
580+
581+
public override void VisitNameEquals(NameEqualsSyntax node)
582+
{
583+
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
584+
585+
for (int i = 0; i < nodesAndTokens.Count; i++)
586+
{
587+
SyntaxNode? asNode = nodesAndTokens[i].AsNode();
588+
589+
if (asNode != null)
590+
{
591+
SyntaxKind kind = asNode.Kind();
592+
593+
switch (kind)
594+
{
595+
case SyntaxKind.IdentifierName:
596+
VisitIdentifierName(asNode as IdentifierNameSyntax);
597+
break;
598+
default:
599+
SM.Log($"asNode : {kind}");
600+
break;
601+
}
602+
}
603+
else
604+
{
605+
SyntaxToken asToken = nodesAndTokens[i].AsToken();
606+
SyntaxKind kind = asToken.Kind();
607+
608+
switch (kind)
609+
{
610+
case SyntaxKind.EqualsToken:
611+
{
612+
JSSB.Append(":");
613+
break;
614+
}
615+
default:
616+
SM.Log($"asToken : {kind}");
617+
break;
618+
}
619+
}
620+
}
621+
}
622+
531623
public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
532624
{
533625
ChildSyntaxList nodesAndTokens = node.ChildNodesAndTokens();
@@ -1772,6 +1864,7 @@ public bool IdentifierToken(SyntaxNode node)
17721864
}
17731865
}
17741866
}
1867+
node = _SNOriginal;
17751868
}
17761869
else
17771870
{
@@ -1919,6 +2012,17 @@ where e.IsKind(SyntaxKind.IdentifierToken)
19192012

19202013
}
19212014

2015+
if (iSymbol != null && iSymbol.ContainingType != null && iSymbol.ContainingType.IsAnonymousType == true)
2016+
{
2017+
if (CustomCSNamesToJS(node) == false)
2018+
{
2019+
VisitLeadingTrivia(identifier);
2020+
JSSB.Append(text);
2021+
VisitTrailingTrivia(identifier);
2022+
}
2023+
return true;
2024+
}
2025+
19222026
foreach (Type type in _Options.CustomCSTypesToJS)
19232027
{
19242028
if (type.Name == text)

0 commit comments

Comments
 (0)