コード例 #1
0
        internal static void Run(CodeGeneratorRequest request, CodeGeneratorResponse.Builder response)
        {
            var arguments = new List<string>();
            foreach (var arg in request.Parameter.Split(' '))
            {
                var timmedArg = (arg ?? "").Trim();
                if (!string.IsNullOrEmpty(timmedArg))
                {
                    arguments.Add(timmedArg);
                }
            }
            // Adding fake input file to make TryValidate happy.
            arguments.Add(System.Reflection.Assembly.GetExecutingAssembly().Location);

            GeneratorOptions options = new GeneratorOptions
            {
                Arguments = arguments
            };
            IList<string> validationFailures;
            if (!options.TryValidate(out validationFailures))
            {
                response.Error += new InvalidOptionsException(validationFailures).Message;
                return;
            }

            Generator generator = Generator.CreateGenerator(options);
            generator.Generate(request, response);
        }
コード例 #2
0
        public void Generate(CodeGeneratorRequest request, CodeGeneratorResponse.Builder response)
        {
            IList<FileDescriptor> descriptors = ConvertDescriptors(options.FileOptions, request.ProtoFileList);

            // Combine with options from command line
            foreach (FileDescriptor descriptor in descriptors)
            {
                descriptor.ConfigureWithDefaultOptions(options.FileOptions);
            }

            bool duplicates = false;
            Dictionary<string, bool> names = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
            foreach (FileDescriptor descriptor in descriptors)
            {
                string file = GetOutputFile(descriptor, false);
                if (names.ContainsKey(file))
                {
                    duplicates = true;
                    break;
                }
                names.Add(file, true);
            }

            //ROK - Changed to dictionary from HashSet to allow 2.0 compile
            var filesToGenerate = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            foreach (var item in request.FileToGenerateList)
            {
                filesToGenerate[item] = null;
            }
            foreach (FileDescriptor descriptor in descriptors)
            {
                // Optionally exclude descriptors in google.protobuf
                if (descriptor.CSharpOptions.IgnoreGoogleProtobuf && descriptor.Package == "google.protobuf")
                {
                    continue;
                }
                if (filesToGenerate.ContainsKey(descriptor.Name))
                {
                    Generate(descriptor, duplicates, response);
                }
            }
        }