Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            AssemblyReflector reflector = new AssemblyReflector();

            reflector.RegisterTypeToDatatype(typeof(bool), new BoolType().Datatype);
            reflector.RegisterTypeToDatatype(typeof(bool?), new NullableBoolType().Datatype);
            reflector.RegisterTypeToDatatype(typeof(Int32?), new NullableInt32Type().Datatype);
            reflector.RegisterTypeToDatatype(typeof(Int32), new Int32Type().Datatype);
            reflector.RegisterTypeToDatatype(typeof(String), new StringType().Datatype);
            reflector.RegisterTypeToDatatype(typeof(List <>), new ListType().Datatype);
            reflector.RegisterTypeToDatatype(typeof(Dictionary <,>), new DictionaryType().Datatype);

            reflector.LoadSchemaAssembly(@"C:\Users\jeremy.lothian\OneDrive\Projects\Anvyl\Anvyl.Experimental.Library\bin\Debug\netcoreapp2.0\Anvyl.Experimental.Library.dll");


            var settings = new JsonSerializerSettings
            {
                ContractResolver = ShouldSerializeContractResolver.Instance,
                Formatting       = Formatting.Indented
            };
            StringBuilder sb = new StringBuilder();

            foreach (DataField df in reflector.FieldsForType)
            {
                Console.WriteLine(df.ToJson());
                sb.AppendLine(df.ToJson().TrimEnd() + ",");
            }
            File.WriteAllText("output.json", "{" + sb.ToString().TrimEnd().TrimEnd(',') + "}");
            //string serialized = JsonConvert.SerializeObject(reflector.FieldsForType, settings);
            //Console.WriteLine(serialized);
            //List<DataField> df = JsonConvert.DeserializeObject<List<DataField>>(serialized);
            //string serialized2 = JsonConvert.SerializeObject(df, settings);
            //if(serialized == serialized2)
            {
                //    Console.WriteLine("Sussesses!");
            }

            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());

            configurationBuilder.AddJsonFile("xpconfig.json");

            var configuration = configurationBuilder.Build();
            var asettings     = configuration.GetSection("Accufiguration").Get <AccufigurationSettings>();


            //validation
            var Validation = new ConfigurationValidationManager();

            Validation.RegisterValidator(new TestValidatorNullableInt32());

            var isValid = Validation.Validate(configuration.GetSection("Accufiguration"), reflector.FieldsForType[0]);

            //JsonExConfigurationProvider jsonProv = new JsonExConfigurationProvider(new JsonConfigurationSource());
            //jsonProv.Save(configuration, configuration, reflector.rootDataField, "**********[MARKED_FOR_DELETE]**********", "outNew.txt");
        }