Exemplo n.º 1
0
        /// <summary>
        /// Execute the code generator against a FileDescriptorSet, yielding a sequence of files
        /// </summary>
        public override IEnumerable <CodeFile> Generate(FileDescriptorSet set, NameNormalizer normalizer = null)
        {
            foreach (var file in set.Files)
            {
                if (!file.IncludeInOutput)
                {
                    continue;
                }

                var fileName = Path.ChangeExtension(file.Name, DefaultFileExtension);

                string generated;
                using (var buffer = new StringWriter())
                {
                    var ctx = new GeneratorContext(file, normalizer ?? NameNormalizer.Default, buffer, Indent);

                    ctx.BuildTypeIndex(); // populates for TryFind<T>
                    WriteFile(ctx, file);
                    generated = buffer.ToString();
                }
                yield return(new CodeFile(fileName, generated));
            }
        }