Пример #1
0
        /// <summary>
        /// Dispatches to the right handler method for writing generated code to output file(s).
        /// </summary>
        /// <param name="generateOptions"></param>
        internal static void HandleGenerateCode(GenerateOptions generateOptions)
        {
            var settingsFromFile = generateOptions.GetConfigInstance(ProgressReporter);
            var settings         = settingsFromFile ?? XObjectsCoreGenerator.LoadLinqToXsdSettings();

            if (settingsFromFile != null)
            {
                PrintLn("Configuration file(s) loaded...".Gray());
            }

            settings.EnableServiceReference = generateOptions.EnableServiceReference;

            var textWriters = generateOptions.AutoConfig
                ? XObjectsCoreGenerator.Generate(generateOptions.SchemaFiles)
                : XObjectsCoreGenerator.Generate(generateOptions.SchemaFiles, settings);

            if (generateOptions.Output.IsEmpty())
            {
                PrintLn("No output directory given: defaulting to same directory as XSD file(s).".Gray());
                generateOptions.Output = "-1";
            }

            var hasCsExt = Path.GetExtension(generateOptions.Output).EndsWith(".cs");

            // merge the output into a single file
            if (hasCsExt)
            {
                GenerateCodeDispatcher.HandleWriteOutputToSingleFile(generateOptions, textWriters);
            }
            else
            {
                GenerateCodeDispatcher.HandleWriteOutputToMultipleFiles(generateOptions, textWriters);
            }
        }
Пример #2
0
        /// <summary>
        /// Dispatches to the right handler method for writing generated code to output file(s).
        /// </summary>
        /// <param name="generateOptions"></param>
        internal static void HandleGenerateCode(GenerateOptions generateOptions)
        {
            var settings = generateOptions.GetConfigInstance(ProgressReporter) ?? XObjectsCoreGenerator.LoadLinqToXsdSettings();

            if (generateOptions.GetConfigInstance() != null)
            {
                Console.WriteLine("Configuration file(s) loaded...");
            }

            settings.EnableServiceReference = generateOptions.EnableServiceReference;

            var textWriters = generateOptions.AutoConfig
                ? XObjectsCoreGenerator.Generate(generateOptions.SchemaFiles)
                : XObjectsCoreGenerator.Generate(generateOptions.SchemaFiles, settings);

            if (generateOptions.Output.IsEmpty())
            {
                if (generateOptions.FoldersWereGiven)
                {
                    Console.WriteLine("No output directory given: defaulting to same directory as XSD file(s).");
                    generateOptions.Output = "-1";
                }
                else
                {
                    generateOptions.Output = Environment.CurrentDirectory;
                    Console.WriteLine($"No output directory given: defaulting to current working directory: {Environment.CurrentDirectory}.");
                }
            }

            var hasCsExt = Path.GetExtension(generateOptions.Output).EndsWith(".cs");

            if (hasCsExt) // merge the output into a single file
            {
                GenerateCodeDispatcher.HandleWriteOutputToSingleFile(generateOptions.Output, textWriters);
            }
            else
            {
                GenerateCodeDispatcher.HandleWriteOutputToMultipleFiles(generateOptions.Output, textWriters);
            }
        }