示例#1
0
        private void ExecuteGenerator(GeneratorExecutionContext context)
        {
            INamedTypeSymbol[] symbols = context
                                         .GetAllTypes()
                                         .ToArray();

            //This finds all the context symbols trying to be generated
            var dataContextSymbols = symbols
                                     .Where(s => s.HasAttributeExact <RequiredDataModelAttribute>())
                                     .ToArray();

            //.Where(s => !s.IsGenericType)
            foreach (var contextSymbol in dataContextSymbols)
            {
                StringBuilder             builder            = new StringBuilder();
                UsingsEmitter             usingsEmitter      = new();
                NamespaceDecoratorEmitter namespaceDecorator = new NamespaceDecoratorEmitter(CreateContextClassEmitter(contextSymbol), contextSymbol.ContainingNamespace.FullNamespaceString());

                usingsEmitter.AddNamespaces(GGDBFConstants.DEFAULT_NAMESPACES);

                foreach (var type in RetrieveModelTypes(contextSymbol))
                {
                    AddNamespacesForType(type, usingsEmitter);
                }

                usingsEmitter.Emit(builder);
                namespaceDecorator.Emit(builder);

                context.AddSource(contextSymbol.Name, ConvertFileToNode(context, builder).ToString());

                EmitSerializableModelTypes(contextSymbol, context);
                EmitModelKeyTypes(contextSymbol, context);
            }
        }