@@ -33,9 +33,11 @@ public RoslynIntrospector(Project project)
33
33
foreach ( var addedProject in changes . GetAddedProjects ( ) )
34
34
projectCompilations . Add ( addedProject . Id , GetCompilationForProject ( addedProject ) ) ;
35
35
foreach ( var projectChanges in changes . GetProjectChanges ( ) )
36
+ {
36
37
//Bruteforce way: Just get the new compilation...
37
38
//If that does not scale try adding documents to the compilation (incremental update)
38
- projectCompilations [ projectChanges . ProjectId ] = GetCompilationForProject ( projectChanges . NewProject ) ;
39
+ //projectCompilations[projectChanges.ProjectId] = GetCompilationForProject(projectChanges.NewProject);
40
+ }
39
41
solution = project . Solution ;
40
42
}
41
43
else
@@ -132,12 +134,54 @@ private INamedTypeSymbol FindClassesWithNameAndAttribute(string fullName, string
132
134
( y . AttributeClass != null && y . AttributeClass . Name . Equals ( attribute ) ) ) ) )
133
135
. OrderByDescending ( x => x . ContainingNamespace . ToDisplayString ( ) )
134
136
. FirstOrDefault ( ) ;
137
+ //var y = comp.GetSymbolsWithName(x => x.Equals(name, System.StringComparison.Ordinal))
138
+ // .OfType<INamedTypeSymbol>()
139
+ // .Where(x => NamespaceUtility.IsPartOf(x.ToDisplayString(), fullName)
140
+ // && (x.GetAttributes().Any(y =>
141
+ // (y.AttributeClass != null && y.AttributeClass.Name.Equals(attributeFull)) ||
142
+ // (y.AttributeClass != null && y.AttributeClass.Name.Equals(attribute)))))
143
+ // .OrderByDescending(x => x.ContainingNamespace.ToDisplayString())
144
+ // .ToList();
145
+
146
+ //if (name == "_DyloAttributes")
147
+ //{
148
+ // var z1 = comp.GetSymbolsWithName(x => x.Equals(name, System.StringComparison.Ordinal)).OfType<INamedTypeSymbol>().ToList();
149
+ // var z2 = comp.GetSymbolsWithName(x => x.Equals(name, System.StringComparison.Ordinal)).ToList();
150
+ // var z3 = comp.GetSymbolsWithName(x => x.IndexOf("_DyloAttributes", StringComparison.OrdinalIgnoreCase) != -1).ToList();
151
+ // var z4 = comp.GetSymbolsWithName(n => true).ToList();
152
+ // //StiftungWarentest.Website.ViewsRelaunch.Shared._DyloAttributes
153
+ // var z5 = z4.Where(n => n.ContainingNamespace.ToString().StartsWith("StiftungWarentest.Website.ViewsRelaunch", StringComparison.OrdinalIgnoreCase)).ToList();
154
+ // Console.WriteLine(z1.Count);
155
+ //}
156
+
135
157
if ( template != null )
136
158
return template ;
137
159
}
138
160
return null ;
139
161
}
140
162
163
+ private IMethodSymbol findHelperMethod ( string funtionName , List < ITypeSymbol > parameters )
164
+ {
165
+ foreach ( var comp in projectCompilations . Values )
166
+ {
167
+ var candidates = comp . GetSymbolsWithName ( x => x . Equals ( funtionName ) )
168
+ . OfType < IMethodSymbol > ( )
169
+ . Where ( x => x . IsStatic &&
170
+ // The check for both HelperMethodAttribute and HelperMethodAttributeFull because when loading a asp.net core project
171
+ // we the attribute name is HelpermethodAttribute while when loading a .net framework project the attribute name is
172
+ // HelperMethodAttribute
173
+ x . GetAttributes ( ) . Any ( y => y . AttributeClass . Name . Equals ( StringConstants . HELPERMETHODATTRIBUTEFULL )
174
+ || y . AttributeClass . Name . Equals ( StringConstants . HELPERMETHODATTRIBUTE ) ) ) ;
175
+ var helperMethod = candidates . FirstOrDefault ( x => DoParametersMatch ( x , parameters ) ) ;
176
+ if ( helperMethod != null )
177
+ {
178
+ return helperMethod ;
179
+ }
180
+ }
181
+ return null ;
182
+ }
183
+
184
+
141
185
/// <summary>
142
186
/// Searches each referenced project for helper methods.
143
187
/// These must serve following conditions:
@@ -149,23 +193,23 @@ private INamedTypeSymbol FindClassesWithNameAndAttribute(string fullName, string
149
193
/// <param name="funtionName">Name of the Helper as declared in the handlebars-template</param>
150
194
/// <param name="parameters">Types of the Parameters that are passed to the helper method</param>
151
195
/// <returns>The MethodSymbol for the called HelperMethod or null if it could not be found</returns>
152
- public IMethodSymbol GetHelperMethod ( string funtionName , List < ITypeSymbol > parameters )
196
+ public IMethodSymbol GetHelperMethod ( string funtionName , List < ITypeSymbol > parameters , out bool acceptsStringBuilder )
153
197
{
154
- foreach ( var comp in projectCompilations . Values )
198
+ //acceptsStringBuilder = false;
199
+ //return findHelperMethod(funtionName, parameters);
200
+
201
+ var sbSymbol = GetStringBuilderTypeSymbol ( ) ;
202
+ parameters . Add ( sbSymbol ) ;
203
+
204
+ IMethodSymbol helperMethod = findHelperMethod ( funtionName , parameters ) ;
205
+ acceptsStringBuilder = true ;
206
+ if ( helperMethod == null )
155
207
{
156
- var candidates = comp . GetSymbolsWithName ( x => x . Equals ( funtionName ) )
157
- . OfType < IMethodSymbol > ( )
158
- . Where ( x => x . IsStatic &&
159
- // The check for both HelperMethodAttribute and HelperMethodAttributeFull because when loading a asp.net core project
160
- // we the attribute name is HelpermethodAttribute while when loading a .net framework project the attribute name is
161
- // HelperMethodAttribute
162
- x . GetAttributes ( ) . Any ( y => y . AttributeClass . Name . Equals ( StringConstants . HELPERMETHODATTRIBUTEFULL )
163
- || y . AttributeClass . Name . Equals ( StringConstants . HELPERMETHODATTRIBUTE ) ) ) ;
164
- var helperMethod = candidates . FirstOrDefault ( x => DoParametersMatch ( x , parameters ) ) ;
165
- if ( helperMethod != null )
166
- return helperMethod ;
208
+ acceptsStringBuilder = false ;
209
+ parameters . Remove ( sbSymbol ) ;
210
+ helperMethod = findHelperMethod ( funtionName , parameters ) ;
167
211
}
168
- return null ;
212
+ return helperMethod ;
169
213
}
170
214
171
215
private static bool DoParametersMatch ( IMethodSymbol methodSymbol , List < ITypeSymbol > parameters )
@@ -207,5 +251,10 @@ public INamedTypeSymbol GetStringTypeSymbol()
207
251
{
208
252
return projectCompilations . First ( ) . Value . GetSpecialType ( SpecialType . System_String ) ;
209
253
}
254
+
255
+ public INamedTypeSymbol GetStringBuilderTypeSymbol ( )
256
+ {
257
+ return projectCompilations . First ( ) . Value . GetTypeByMetadataName ( @"System.Text.StringBuilder" ) ;
258
+ }
210
259
}
211
260
}
0 commit comments