@@ -94,7 +94,7 @@ public static SyntaxSymbol GetResponseType(TypeDeclarationSyntax syntax, INamedT
94
94
else if ( syntax . BaseList ? . Types . Select ( z => z . Type ) . OfType < SimpleNameSyntax > ( ) . Any ( z => z . Identifier . Text == "IRequest" || z . Identifier . Text == "IJsonRpcRequest" )
95
95
== true )
96
96
{
97
- type = ParseTypeName ( syntax . Identifier . ToFullString ( ) ) ;
97
+ type = IdentifierName ( syntax . Identifier . Text ) ;
98
98
}
99
99
else
100
100
{
@@ -848,10 +848,6 @@ public static ArrowExpressionClauseSyntax GetPartialInvokeExpression(TypeSyntax
848
848
849
849
private static string SpecialCasedHandlerFullName ( INamedTypeSymbol symbol )
850
850
{
851
- if ( symbol . IsGenericType )
852
- {
853
- }
854
-
855
851
var substringIndex = symbol . Name . LastIndexOf ( "Handler" , StringComparison . Ordinal ) ;
856
852
if ( substringIndex is - 1 )
857
853
{
@@ -880,12 +876,7 @@ private static string SpecialCasedHandlerFullName(INamedTypeSymbol symbol)
880
876
substringIndex -= 1 ;
881
877
}
882
878
883
- return new Regex ( @"(\w+(?:\<\w+\>)?)$" )
884
- . Replace (
885
- symbol . ToDisplayString ( ) ,
886
- symbol . Name . Substring ( start , substringIndex )
887
- )
888
- ;
879
+ return symbol . Name . Substring ( start , substringIndex ) ;
889
880
}
890
881
891
882
public static string SpecialCasedHandlerName ( INamedTypeSymbol symbol )
@@ -930,6 +921,54 @@ public static SyntaxList<TypeParameterConstraintClauseSyntax> HandlerIdentityCon
930
921
) ;
931
922
}
932
923
924
+ public static class LazyFactory
925
+ {
926
+ public static Lazy < T > Create < T > ( Func < T > func ) => new ( func ) ;
927
+ }
928
+
929
+ public static class CommonElements
930
+ {
931
+ public static AccessorListSyntax GetSetAccessor => GetSetAccessorLazy . Value ;
932
+
933
+ private static readonly Lazy < AccessorListSyntax > GetSetAccessorLazy = LazyFactory . Create (
934
+ ( ) => AccessorList (
935
+ List (
936
+ new [ ] {
937
+ AccessorDeclaration ( SyntaxKind . GetAccessorDeclaration ) . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
938
+ AccessorDeclaration ( SyntaxKind . SetAccessorDeclaration ) . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) )
939
+ }
940
+ )
941
+ )
942
+ ) ;
943
+
944
+ private static readonly Lazy < AccessorListSyntax > GetInitAccessorLazy = LazyFactory . Create (
945
+ ( ) => AccessorList (
946
+ List (
947
+ new [ ] {
948
+ AccessorDeclaration ( SyntaxKind . GetAccessorDeclaration )
949
+ . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ,
950
+ AccessorDeclaration ( SyntaxKind . InitAccessorDeclaration )
951
+ . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) )
952
+ }
953
+ )
954
+ )
955
+ ) ;
956
+
957
+ public static AccessorListSyntax GetInitAccessor => GetInitAccessorLazy . Value ;
958
+
959
+ private static readonly Lazy < AccessorListSyntax > GetAccessorLazy = LazyFactory . Create (
960
+ ( ) => AccessorList (
961
+ List (
962
+ new [ ] {
963
+ AccessorDeclaration ( SyntaxKind . GetAccessorDeclaration ) . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) )
964
+ }
965
+ )
966
+ )
967
+ ) ;
968
+
969
+ public static AccessorListSyntax GetAccessor => GetAccessorLazy . Value ;
970
+ }
971
+
933
972
public static class SyntaxExtensions
934
973
{
935
974
public static TypeSyntax EnsureNullable ( this TypeSyntax typeSyntax ) => typeSyntax is NullableTypeSyntax nts ? nts : NullableType ( typeSyntax ) ;
@@ -940,7 +979,7 @@ public static class SyntaxExtensions
940
979
return typeSyntax switch {
941
980
SimpleNameSyntax sns => sns . Identifier . Text ,
942
981
QualifiedNameSyntax qns => qns . Right . Identifier . Text ,
943
- NullableTypeSyntax nts => nts . ElementType . GetSyntaxName ( ) ,
982
+ NullableTypeSyntax nts => nts . ElementType . GetSyntaxName ( ) ,
944
983
_ => throw new NotSupportedException ( typeSyntax . GetType ( ) . FullName )
945
984
} ;
946
985
}
@@ -987,6 +1026,35 @@ public static bool ContainsAttribute(this in SyntaxList<AttributeListSyntax> lis
987
1026
return false ;
988
1027
}
989
1028
1029
+ public static AttributeSyntax ? GetAttribute ( this AttributeListSyntax list , string attributePrefixes ) // string is comma separated
1030
+ {
1031
+ if ( list is { Attributes : { Count : 0 } } ) return null ;
1032
+ var names = GetNames ( attributePrefixes ) ;
1033
+
1034
+ foreach ( var item in list . Attributes )
1035
+ {
1036
+ if ( item . Name . GetSyntaxName ( ) is { } n && names . Contains ( n ) ) return item ;
1037
+ }
1038
+
1039
+ return null ;
1040
+ }
1041
+
1042
+ public static AttributeSyntax ? GetAttribute ( this in SyntaxList < AttributeListSyntax > list , string attributePrefixes ) // string is comma separated
1043
+ {
1044
+ if ( list is { Count : 0 } ) return null ;
1045
+ var names = GetNames ( attributePrefixes ) ;
1046
+
1047
+ foreach ( var item in list )
1048
+ {
1049
+ foreach ( var attribute in item . Attributes )
1050
+ {
1051
+ if ( attribute . Name . GetSyntaxName ( ) is { } n && names . Contains ( n ) ) return attribute ;
1052
+ }
1053
+ }
1054
+
1055
+ return null ;
1056
+ }
1057
+
990
1058
public static bool IsAttribute ( this AttributeSyntax attributeSyntax , string attributePrefixes ) // string is comma separated
991
1059
{
992
1060
var names = GetNames ( attributePrefixes ) ;
0 commit comments