Beispiel #1
0
        public static CodeGenerationConfig GetConfig(SourceFileSymbolVisitor visitor, SourceGeneratorContext context)
        {
            string file = File.ReadAllText("codegen.json");
            CodeGenerationConfig config = JSON.Parse <CodeGenerationConfig>(file);

            if (config != null)
            {
            }
            return(config);
        }
        public void Initialize(InitializationContext context)
        {
            Debugger.Launch();

            _logger = new Logger();
            _logger.RegisterFactory(new ConsoleLogOutputFactory("General Logging", LogScope.Error | LogScope.Warning | LogScope.Information));

            _renderEngine     = new RenderEngine(_logger);
            _generationEngine = new GenerationEngine(_logger);

            _visitor = new SourceFileSymbolVisitor();
        }
        public List <INamedItem> GetMatchedObjects(SourceGeneratorContext context, SourceFileSymbolVisitor visitor, CodeGenerationConfigBuilder builder)
        {
            visitor.Visit(context.Compilation.GlobalNamespace);

            builder.Input.Assemblies ??= new List <string>();

            if (!builder.Input.Assemblies.Any())
            {
                builder.Input.Assemblies.Add(context.Compilation.Assembly.Name);
            }

            List <INamedItem> queryObjects = new List <INamedItem>();

            if (!string.IsNullOrEmpty(builder.Input.InputMatcher))
            {
                List <INamedItem> matchedObjects = visitor.QueryObjects(builder.Input.InputMatcher, builder.Input.Assemblies);
                if (matchedObjects != null)
                {
                    queryObjects.AddRange(matchedObjects);
                }
            }

            if (builder.Input.InputMatchers != null && builder.Input.InputMatchers.Any())
            {
                foreach (string matcher in builder.Input.InputMatchers)
                {
                    List <INamedItem> matchedObjects = visitor.QueryObjects(matcher, builder.Input.Assemblies);
                    if (matchedObjects != null)
                    {
                        queryObjects.AddRange(matchedObjects);
                    }
                }
            }

            if (builder.Input.InputIgnoreMatchers != null && builder.Input.InputIgnoreMatchers.Any())
            {
                foreach (string matcher in builder.Input.InputIgnoreMatchers)
                {
                    List <INamedItem> matchedObjects = visitor.QueryObjects(matcher, builder.Input.Assemblies);
                    if (matchedObjects != null)
                    {
                        foreach (INamedItem match in matchedObjects)
                        {
                            queryObjects = queryObjects.Where(o => o.FullName != match.FullName).ToList();
                        }
                    }
                }
            }

            return(queryObjects);
        }