Exemple #1
0
        static void Main(string[] args)
        {
            // Serialize our settings object from a JSON string
            Settings settings = new Settings();

            Console.WriteLine("Settings Values before Serialize \n");
            Console.WriteLine("   The property value Enabled        is :   {0}", settings.enabled);
            Console.WriteLine("   The property value MyProperty     is :   {0}", settings.MyProperty);
            Console.WriteLine("   The property value NameProperty   is :   {0}", settings.NameProperty);
            Console.WriteLine("   The property value points         is :   {0}", settings.points);
            Console.WriteLine("   The property value Summary        is :   {0}", settings.Summary);
            Console.WriteLine("\n");

            var result = GenericValidator.TryValidate(settings);

            Console.WriteLine("Are the data valid? : {0} \n", result);

            //If the data are valid then it is serialized
            if (result)
            {
                string jsonString;
                jsonString = settings.Serialize();

                Console.WriteLine("Result Serialized : {0} \n", jsonString);

                settings.Deserialize(jsonString);
            }
        }
Exemple #2
0
        public virtual string Serialize()
        {
            string jsonString;

            jsonString = JsonSerializer.Serialize(this);

            var result = GenericValidator.TryValidate(this);

            return(jsonString);
        }