通过NameValuePairsValueProvider对象来获取指定前缀的Key
2015-10-20 11:18
399 查看
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", "123456789"}, {"contact.EmailAddress", "zhangsan@gmail.com"}, {"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(); } } }
相关文章推荐
- Java中的String类和StringBuilder类复习
- Easyui Form增加myLoad方法,使其支持二级数据对象,Fix版本
- Linguistic Data Consortium (LDC)
- druid连接池配置
- Leetcode108: Unique Binary Search Trees II
- Version和Build的区别
- NGUI坑之首行缩进
- AndroidUI-TxetView嵌套Html的使用
- UITabbar UINavigationBar
- 【最新API翻译】 Bluetooth--BluetoothAdapter API 翻译
- Qt使用教程之创建Qt Quick项目
- 「8-Queens Problem」皇后问题局部极值启发式搜索方法
- UINavigationItem UINavigationBar 关系分析
- STL学习笔记——序列式容器deque
- 浅谈UIScrollView
- VS2005编译问题LINK : E:/aaa/Debug/aaa.exe not found or not built by the last incremental link; performin
- 开速开发:UIView与XIB关联
- easyui 批量 移除行,
- QT小例子GUI(主)线程与子线程之间的通信
- require.js的用法详解