예제 #1
0
        private static List<GeneratorParameters> ReadParametersFromCommandLine(IReadOnlyDictionary<string, object> argDictionary)
        {
            var assemblyLoader = new AssemblyLoader();

            var generatorParameters = GeneratorParameters.Create();

            var assemblyNames = ReadStringParameter(argDictionary, "assembly");
            if (assemblyNames.Any())
            {
                var assembly = assemblyLoader.Load(assemblyNames.First());
                generatorParameters.SetAssembly(assembly);
            }

            var referenceNames = ReadStringParameter(argDictionary, "reference");
            var references = referenceNames.Select(assemblyLoader.Load);
            generatorParameters.AddReferences(references);

            var withDocs = argDictionary.ContainsKey("withdocs");
            generatorParameters.SetWithDocumentation(withDocs);

            var ignoredNamespaces = ReadStringParameter(argDictionary, "ignore");
            foreach (var ignoredNamespace in ignoredNamespaces)
            {
                generatorParameters.AddIgnoreNamespace(ignoredNamespace);
            }

            var regexIgnoreStrings = ReadStringParameter(argDictionary, "ignoreRegex");
            foreach (var regexString in regexIgnoreStrings)
            {
                generatorParameters.AddIgnoreNamespaceByRegex(regexString);
            }

            var headerLines = ReadStringParameter(argDictionary, "headerLine");
            foreach (var headerLine in headerLines)
            {
                generatorParameters.AddHeaderLine(headerLine);
            }

            var headerFile = ReadStringParameter(argDictionary, "headerFile").FirstOrDefault();
            if (!string.IsNullOrEmpty(headerFile))
            {
                generatorParameters.AddHeaderFile(headerFile);
            }

            var outputFilePath = ReadStringParameter(argDictionary, "outputFilePath").FirstOrDefault();
            if (!string.IsNullOrEmpty(outputFilePath))
            {
                generatorParameters.SetOutputFilePath(outputFilePath);
            }

            return new List<GeneratorParameters> { generatorParameters };
        }
예제 #2
0
        private static List<GeneratorParameters> ReadParametersFromConfigurationFile(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new GeneratorException($"Could not find file {filename}");
            }

            var assemblyLoader = new AssemblyLoader();
            var generatorFileReader = new GeneratorParametersReader(assemblyLoader);

            List<GeneratorParameters> generatorParameters;
            using (var fileStream = File.OpenText(filename))
            {
                generatorParameters = generatorFileReader.ReadFromStream(fileStream).ToList();
            }
            return generatorParameters;
        }