コード例 #1
0
        static void Main(string[] args)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("contacts[0].Name", "张三");
            dictionary.Add("contacts[0].PhoneNo", "123456789");
            dictionary.Add("contacts[0].EmailAddress", "*****@*****.**");
            dictionary.Add("contacts[1].Name", "李四");
            dictionary.Add("contacts[1].PhoneNo", "987654321");
            dictionary.Add("contacts[1].EmailAddress", "*****@*****.**");

            NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null);

            //Prefix=""
            Console.WriteLine("Prefix: <Empty>");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            IDictionary <string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty);

            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contact"
            Console.WriteLine("\nPrefix: contact");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contact");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contacts[0]"
            Console.WriteLine("\nPrefix: contacts[0]");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contacts[0]");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contacts[1]"
            Console.WriteLine("\nPrefix: contacts[1]");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contacts[1]");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("contact.Name", "张三");
            dictionary.Add("contact.PhoneNo", "123456789");
            dictionary.Add("contact.EmailAddress", "*****@*****.**");
            dictionary.Add("contact.Address.Province", "江苏");
            dictionary.Add("contact.Address.City", "苏州");
            dictionary.Add("contact.Address.District", "工业园区");
            dictionary.Add("contact.Address.Street", "星湖街328号");
            NameValuePairsValueProvider valueProvider = new NameValuePairsValueProvider(dictionary.ToArray(), null);

            //Prefix=""
            Console.WriteLine("Prefix: <Empty>");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            IDictionary <string, string> keys = valueProvider.GetKeysFromPrefix(string.Empty);

            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contact"
            Console.WriteLine("\nPrefix: contact");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contact");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }

            //Prefix="contact.Address"
            Console.WriteLine("\nPrefix: contact.Address");
            Console.WriteLine("{0,-14}{1}", "Key", "Value");
            keys = valueProvider.GetKeysFromPrefix("contact.Address");
            foreach (var item in keys)
            {
                Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
            }
        }