using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.ValueProviders.Providers; namespace ConsoleApp
{
internal class Program
{
private static void Main(string[] args)
{
var dic = new Dictionary<string, string>
{
{"contact.Name", "张三"},
{"contact.PhoneNo", ""},
{"contact.EmailAddress", "[email protected]"},
{"contact.Address.Province", "上海"},
{"contact.Address.City", "上海"},
{"contact.Address.District", "长宁区"},
{"contact.Address.Street", "金钟路968号"}
};
var valueProvider = new NameValuePairsValueProvider(dic.ToArray(), null); // prefix=""
Console.WriteLine("Prefix: <Empty>");
Console.WriteLine("{0,-14}{1}", "key", "value");
var keys = valueProvider.GetKeysFromPrefix(string.Empty);
foreach (var item in keys)
{
Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
} // Prefix="contact"
Console.WriteLine("Prefix: 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"
Console.WriteLine("Prefix: 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);
} Console.Read();
}
}
}
04-15 05:02