File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
src/SourceGeneration.Reflection.SourceGenerator/Extensions Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1
1
using Microsoft . CodeAnalysis ;
2
+ using Microsoft . CodeAnalysis . CSharp . Syntax ;
2
3
using System . Linq ;
3
4
using System . Text ;
5
+ using System . Threading ;
4
6
5
7
namespace SourceGeneration . Reflection . SourceGenerator ;
6
8
@@ -97,4 +99,32 @@ public static bool IsCompliantGenericEnumerableInterface(this ITypeSymbol type)
97
99
return type . AllInterfaces . Any ( x => x . IsGenericType && x . Name == "IEnumerable" ) ;
98
100
}
99
101
102
+ public static string GetInitializeValue ( this IFieldSymbol field , CancellationToken cancellationToken )
103
+ {
104
+ if ( field . DeclaringSyntaxReferences . Length > 0 )
105
+ {
106
+ var syntax = field . DeclaringSyntaxReferences [ 0 ] . GetSyntax ( cancellationToken ) ;
107
+ if ( syntax is VariableDeclaratorSyntax declaration &&
108
+ declaration . Initializer is EqualsValueClauseSyntax equalsValueClause )
109
+ {
110
+ return equalsValueClause . Value . ToFullString ( ) ;
111
+ }
112
+ }
113
+ return null ;
114
+ }
115
+
116
+ public static string GetInitializeValue ( this IPropertySymbol property , CancellationToken cancellationToken )
117
+ {
118
+ if ( property . DeclaringSyntaxReferences . Length > 0 )
119
+ {
120
+ var syntax = property . DeclaringSyntaxReferences [ 0 ] . GetSyntax ( cancellationToken ) ;
121
+ if ( syntax is PropertyDeclarationSyntax declaration &&
122
+ declaration . Initializer is EqualsValueClauseSyntax equalsValueClause )
123
+ {
124
+ return equalsValueClause . Value . ToFullString ( ) ;
125
+ }
126
+ }
127
+ return null ;
128
+ }
129
+
100
130
}
You can’t perform that action at this time.
0 commit comments