コード例 #1
0
 public CodeGenerationTestBase()
 {
     TestFileSystem = new TestFileSystem();
     Settings       = TestSettings.MakeSettings();
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: tommyliu86/jschema
        private static int Run(Options options)
        {
            int exitCode = 1;

            try
            {
                string     jsonText = File.ReadAllText(options.SchemaFilePath);
                JsonSchema schema   = SchemaReader.ReadSchema(jsonText, options.SchemaFilePath);

                HintDictionary hintDictionary = null;
                if (options.CodeGenHintsPath != null)
                {
                    if (!File.Exists(options.CodeGenHintsPath))
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.ErrorHintsFileNotFound,
                                      options.CodeGenHintsPath));
                    }

                    string hintDictionaryText = File.ReadAllText(options.CodeGenHintsPath);
                    hintDictionary = new HintDictionary(hintDictionaryText, options.TypeNameSuffix);
                }

                string copyrightNotice = null;
                if (options.CopyrightFilePath != null)
                {
                    if (!File.Exists(options.CopyrightFilePath))
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.ErrorCopyrightFileNotFound,
                                      options.CopyrightFilePath));
                    }

                    copyrightNotice = File.ReadAllText(options.CopyrightFilePath);
                }

                DataModelGeneratorSettings settings = new DataModelGeneratorSettings
                {
                    OutputDirectory           = options.OutputDirectory,
                    TypeNameSuffix            = options.TypeNameSuffix,
                    ForceOverwrite            = options.ForceOverwrite,
                    NamespaceName             = options.NamespaceName,
                    RootClassName             = options.RootClassName,
                    SchemaName                = options.SchemaName,
                    CopyrightNotice           = copyrightNotice,
                    HintDictionary            = hintDictionary,
                    GenerateEqualityComparers = options.GenerateEqualityComparers,
                    GenerateCloningCode       = options.GenerateCloningCode,
                    SealClasses               = options.SealClasses
                };

                new DataModelGenerator(settings).Generate(schema);

                exitCode = 0;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.Error,
                        ex.Message));
            }

            return(exitCode);
        }