void CollectExtensionMethods(SourceGeneratorContext context) { logger.Info("Collecting extension methods with interface constraints!"); foreach (var method in hyperlinqNamespace .GetTypeMembers() .Where(type => type.IsPublic() && type.IsStatic) .SelectMany(type => type.GetMembers() .OfType <IMethodSymbol>() .Where(method => method.IsPublic() && method.IsExtensionMethod && !method.ShouldIgnore(context.Compilation)))) { var extensionType = method.Parameters[0].Type; var generic = method.TypeParameters .FirstOrDefault(parameter => parameter.Name == extensionType.Name && parameter.ConstraintTypes.Length != 0); if (generic is object) { var extendedType = generic.ConstraintTypes[0]; var key = extendedType.OriginalDefinition.MetadataName; if (!collectedExtensionMethods.TryGetValue(key, out var list)) { list = new List <IMethodSymbol>(); collectedExtensionMethods.Add(key, list); } list.Add(method); } } }
public override void Execute(SourceGeneratorContext context) { //_ = Debugger.Launch(); // uncomment to debug code generator logger = context.GetLogger(); logger.Info("Executing Hyperlinq generator!"); var compilation = context.Compilation; hyperlinqNamespace = compilation.SourceModule.GlobalNamespace.GetNamespace("NetFabric", "Hyperlinq"); CollectExtensionMethods(context); GenerateSource(context); }