public static bool underscores()
 {
     Person p = new Person();
     p.p_name = "Foo";
     p.p_email = "*****@*****.**";
     return true;
 }
Exemple #2
0
        public static bool SerializeSimpleClassTest()
        {
            try
            {
                Person friend = new Person()
                {
                    FirstName = "Bob",
                    LastName = "Smith",
                    Birthday = new DateTime(1983, 7, 3),
                    ID = 2,
                    Address = "123 Some St",
                    ArrayProperty = new string[] { "hi", "planet" },
                };
                Person person = new Person() 
                { 
                    FirstName = "John", 
                    LastName = "Doe", 
                    Birthday = new DateTime(1988, 4, 23), 
                    ID = 27, 
                    Address = null,
                    ArrayProperty = new string[] { "hello", "world" },
                    Friend = friend
                };
                string json = JsonSerializer.SerializeObject(person);
                string correctValue = "{\"Address\":null,\"ArrayProperty\":[\"hello\",\"world\"],\"ID\":27,\"Birthday\":\"1988-04-23T00:00:00.000Z\",\"LastName\":\"Doe\",\"Friend\""
                    + ":{\"Address\":\"123 Some St\",\"ArrayProperty\":[\"hi\",\"planet\"],\"ID\":2,\"Birthday\":\"1983-07-03T00:00:00.000Z\",\"LastName\":\"Smith\",\"Friend\":null,\"FirstName\":\"Bob\"}"
                    +",\"FirstName\":\"John\"}";
                if (json != correctValue)
                {
                    Debug.Print("Fail: SerializeSimpleClassTest - Values did not match");
                    return false;
                }

                Debug.Print("Success: SerializeSimpleClassTest");
                return true;
            }
            catch (Exception ex)
            {
                Debug.Print("Fail: SerializeSimpleClassTest - " + ex.Message);
                return false;
            }
        } 
 private void Init()
 {
     Person = new Person { FirstName = "Bill", LastName = "Gates", Address = "Earth", Age = 42 };
     PersonBindingSource.DataSource = Person;
 }