@@ -36,6 +36,7 @@ internal class Walker : CSharpSyntaxWalker, ILog
3636 private bool _ConstKeyword = false ;
3737 private bool _IgnoreArrayType = false ;
3838 private bool _IgnoreAsParenthesis = false ;
39+ private bool _IgnoreTailingDot = false ;
3940
4041 private int _EnumMembers = 0 ;
4142
@@ -773,6 +774,63 @@ public override void VisitArgument(ArgumentSyntax node)
773774 }
774775 }
775776
777+ public override void VisitMemberAccessExpression ( MemberAccessExpressionSyntax node )
778+ {
779+ ChildSyntaxList nodesAndTokens = node . ChildNodesAndTokens ( ) ;
780+
781+ for ( int i = 0 ; i < nodesAndTokens . Count ; i ++ )
782+ {
783+ SyntaxNode ? asNode = nodesAndTokens [ i ] . AsNode ( ) ;
784+
785+ if ( asNode != null )
786+ {
787+ SyntaxKind kind = asNode . Kind ( ) ;
788+
789+ switch ( kind )
790+ {
791+ case SyntaxKind . IdentifierName :
792+ VisitIdentifierName ( ( IdentifierNameSyntax ) asNode ) ;
793+ break ;
794+ case SyntaxKind . ThisExpression :
795+ VisitThisExpression ( ( ThisExpressionSyntax ) asNode ) ;
796+ break ;
797+ case SyntaxKind . ParenthesizedExpression :
798+ VisitParenthesizedExpression ( ( ParenthesizedExpressionSyntax ) asNode ) ;
799+ break ;
800+ case SyntaxKind . InvocationExpression :
801+ case SyntaxKind . ElementAccessExpression :
802+ case SyntaxKind . SimpleMemberAccessExpression :
803+ case SyntaxKind . MemberBindingExpression :
804+ Visit ( asNode ) ;
805+ break ;
806+ default :
807+ _Log . ErrorLine ( $ "asNode : { kind } ") ;
808+ break ;
809+ }
810+ }
811+ else
812+ {
813+ SyntaxToken asToken = nodesAndTokens [ i ] . AsToken ( ) ;
814+ SyntaxKind kind = asToken . Kind ( ) ;
815+
816+ switch ( kind )
817+ {
818+ case SyntaxKind . DotToken :
819+ {
820+ if ( _IgnoreTailingDot )
821+ _IgnoreTailingDot = false ;
822+ else
823+ VisitToken ( asToken ) ;
824+
825+ break ;
826+ }
827+ default :
828+ _Log . ErrorLine ( $ "asToken : { kind } ") ;
829+ break ;
830+ }
831+ }
832+ }
833+ }
776834 public override void VisitAnonymousObjectCreationExpression ( AnonymousObjectCreationExpressionSyntax node )
777835 {
778836 ChildSyntaxList nodesAndTokens = node . ChildNodesAndTokens ( ) ;
@@ -2746,8 +2804,8 @@ public bool IdentifierToken(SyntaxNode node)
27462804 catch ( Exception e )
27472805 {
27482806 symbolInfo = null ;
2749- var a = _Model . GetDeclarationDiagnostics ( ) ;
2750- foreach ( Diagnostic item in a )
2807+ ImmutableArray < Diagnostic > diags = _Model . GetDeclarationDiagnostics ( ) ;
2808+ foreach ( Diagnostic item in diags )
27512809 {
27522810 _Log . WarningLine ( item . ToString ( ) ) ;
27532811 }
@@ -2767,39 +2825,64 @@ public bool IdentifierToken(SyntaxNode node)
27672825 {
27682826 if ( iSymbol . ContainingNamespace . ToString ( ) . Contains ( nameof ( CSharpToJavaScript ) ) )
27692827 {
2828+ //
2829+ //
2830+ //Checking attribute data of a types, see Utils/Attributes.
2831+
2832+ //Attributes of this node(type)
27702833 ImmutableArray < AttributeData > _attributeDatas = iSymbol . GetAttributes ( ) ;
27712834 foreach ( AttributeData _attr in _attributeDatas )
27722835 {
2773- if ( _attr . AttributeClass . Name == nameof ( ValueAttribute ) )
2836+ if ( _attr . AttributeClass . Name == nameof ( EnumValueAttribute ) )
27742837 {
2775- ValueAttribute _attrLocal = new ( _attr . ConstructorArguments [ 0 ] . Value as string ) ;
2838+ EnumValueAttribute _attrLocal = new ( _attr . ConstructorArguments [ 0 ] . Value as string ) ;
27762839
27772840 VisitLeadingTrivia ( identifier ) ;
2778-
2779- //Todo? Better delete the dot, elsewhere.
2780- JSSB . Remove ( JSSB . Length - 1 , 1 ) ;
2781-
27822841 JSSB . Append ( $ "\" { _attrLocal . Value } \" ") ;
27832842 VisitTrailingTrivia ( identifier ) ;
27842843 return true ;
27852844 }
27862845
2846+ if ( _attr . AttributeClass . Name == nameof ( ValueAttribute ) )
2847+ {
2848+ ValueAttribute _attrLocal = new ( _attr . ConstructorArguments [ 0 ] . Value as string ) ;
2849+
2850+ VisitLeadingTrivia ( identifier ) ;
2851+ JSSB . Append ( $ "{ _attrLocal . Value } ") ;
2852+ VisitTrailingTrivia ( identifier ) ;
2853+ return true ;
2854+ }
2855+
27872856 if ( _attr . AttributeClass . Name == nameof ( ToAttribute ) )
27882857 {
27892858 ToAttribute _attrLocal = new ( _attr . ConstructorArguments [ 0 ] . Value as string ) ;
27902859
2860+ if ( _attrLocal . To == ToAttribute . None )
2861+ _IgnoreTailingDot = true ;
2862+
27912863 VisitLeadingTrivia ( identifier ) ;
27922864 JSSB . Append ( $ "{ _attrLocal . Convert ( text ) } ") ;
27932865 VisitTrailingTrivia ( identifier ) ;
27942866 return true ;
2867+
27952868 }
27962869 }
2797- //if (_attributeDatas.Length == 0)
2798- //{
2870+
2871+ //Attributes of a parent node(type)
27992872 _attributeDatas = iSymbol . ContainingType . GetAttributes ( ) ;
28002873 foreach ( AttributeData _attr in _attributeDatas )
28012874 {
2802- if ( _attr . AttributeClass . Name == nameof ( ToAttribute ) )
2875+ if ( _attr . AttributeClass . Name == nameof ( ValueAttribute ) )
2876+ {
2877+ ValueAttribute _attrLocal = new ( _attr . ConstructorArguments [ 0 ] . Value as string ) ;
2878+
2879+ VisitLeadingTrivia ( identifier ) ;
2880+ JSSB . Append ( $ "{ _attrLocal . Value } ") ;
2881+ VisitTrailingTrivia ( identifier ) ;
2882+ return true ;
2883+ }
2884+
2885+ if ( _attr . AttributeClass ? . Name == nameof ( ToAttribute ) )
28032886 {
28042887 ToAttribute _attrLocal = new ( _attr . ConstructorArguments [ 0 ] . Value as string ) ;
28052888
@@ -2809,7 +2892,6 @@ public bool IdentifierToken(SyntaxNode node)
28092892 return true ;
28102893 }
28112894 }
2812- //}
28132895 }
28142896
28152897 if ( iSymbol . ContainingNamespace . ToString ( ) . Contains ( _NameSpaceStr ) )
@@ -2830,9 +2912,9 @@ public bool IdentifierToken(SyntaxNode node)
28302912 return false ;
28312913 }
28322914
2833- SyntaxList < MemberDeclarationSyntax > a = _class . Members ;
2915+ SyntaxList < MemberDeclarationSyntax > _members = _class . Members ;
28342916
2835- foreach ( MemberDeclarationSyntax item in a )
2917+ foreach ( MemberDeclarationSyntax item in _members )
28362918 {
28372919 SyntaxToken _sT = default ;
28382920 if ( item is MethodDeclarationSyntax m )
@@ -2908,11 +2990,18 @@ where e.IsKind(SyntaxKind.IdentifierToken)
29082990 object [ ] _attrs = type . GetCustomAttributes ( true ) ;
29092991 foreach ( object _attr in _attrs )
29102992 {
2911- ToAttribute ? _authAttr = _attr as ToAttribute ;
2912- if ( _authAttr != null )
2993+
2994+ if ( _attr is ValueAttribute valueAttribute )
2995+ {
2996+ VisitLeadingTrivia ( identifier ) ;
2997+ JSSB . Append ( $ "{ valueAttribute . Value } ") ;
2998+ VisitTrailingTrivia ( identifier ) ;
2999+ return true ;
3000+ }
3001+ if ( _attr is ToAttribute toAttribute )
29133002 {
29143003 VisitLeadingTrivia ( identifier ) ;
2915- JSSB . Append ( $ "{ _authAttr . Convert ( text ) } ") ;
3004+ JSSB . Append ( $ "{ toAttribute . Convert ( text ) } ") ;
29163005 return true ;
29173006 }
29183007 }
@@ -2942,10 +3031,17 @@ bool _CheckMembersInNestedClasses(MemberInfo[] _members)
29423031
29433032 foreach ( object _attr in _attrs )
29443033 {
2945- ToAttribute ? _authAttr = _attr as ToAttribute ;
2946- if ( _authAttr != null )
3034+ if ( _attr is ValueAttribute valueAttribute )
3035+ {
3036+ VisitLeadingTrivia ( identifier ) ;
3037+ JSSB . Append ( $ "{ valueAttribute . Value } ") ;
3038+ VisitTrailingTrivia ( identifier ) ;
3039+ return true ;
3040+ }
3041+ if ( _attr is ToAttribute toAttribute )
29473042 {
2948- JSSB . Append ( $ "{ _authAttr . Convert ( text ) } ") ;
3043+ VisitLeadingTrivia ( identifier ) ;
3044+ JSSB . Append ( $ "{ toAttribute . Convert ( text ) } ") ;
29493045 return true ;
29503046 }
29513047 }
0 commit comments