Building ISG pipeline to collect all types if type has changed or changed its constructor #71648
-
Hello. Imagine, I need an ISG which collects all constructors inside every type of the assembly and builds somethings like this: public static class ConstructorInfoProvider
{
public string GetAllConstructorsInfo() => @"
global::MyType(global::System.String a, global::System.Int32 b);
...
"; //this is constructor list
} I understand that last step of this ISG will be expensive since ISG produced a big portion of the code. I need to regenerate this code
Usually, programmers do not change the constructor or added types often, so, I hope that last (expensive) step of ISG pipeline will be called rarely. My question is how to organize ISG pipeline efficiently? Looks like I can build the following pipeline: var step1 = context.CompilationProvider.SelectMany(
(compilation, ct) =>
{
var result = new List<INamedTypeSymbol>(
compilation.Assembly.TypeNames.Count //preallocate
);
result.AddRange(compilation.Assembly.GlobalNamespace.GetAllTypes());
return result.ConverAll(r => new EquatableConstructorsInfo(r)).ToImmutableArray();
}
);
//then Collect info from step1
//then context.RegisterSourceOutput collected info where but I'm afraid that this first step is very expensive, since ISG need to iterate all assembly's types. Are these my considerations true? Or this is not expensive as much? The other approach: is it possible to implement the same pipeline starting from Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This would be extremely expensive in any world. Consider moving to a model where the relevant constructors are marked with an attribute. WTH that, you can use ForAttributeWithMetadataName to easily get the results indexed and provided to you with minimal cost and effort |
Beta Was this translation helpful? Give feedback.
This would be extremely expensive in any world. Consider moving to a model where the relevant constructors are marked with an attribute. WTH that, you can use ForAttributeWithMetadataName to easily get the results indexed and provided to you with minimal cost and effort