zoukankan      html  css  js  c++  java
  • 通过NameValuePairsValueProvider对象来获取指定前缀的Key

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web.Http.ValueProviders.Providers;
     5 
     6 namespace ConsoleApp
     7 {
     8     internal class Program
     9     {
    10         private static void Main(string[] args)
    11         {
    12             var dic = new Dictionary<string, string>
    13             {
    14                 {"contact.Name", "张三"},
    15                 {"contact.PhoneNo", "123456789"},
    16                 {"contact.EmailAddress", "zhangsan@gmail.com"},
    17                 {"contact.Address.Province", "上海"},
    18                 {"contact.Address.City", "上海"},
    19                 {"contact.Address.District", "长宁区"},
    20                 {"contact.Address.Street", "金钟路968号"}
    21             };
    22             var valueProvider = new NameValuePairsValueProvider(dic.ToArray(), null);
    23 
    24             // prefix=""
    25             Console.WriteLine("Prefix: <Empty>");
    26             Console.WriteLine("{0,-14}{1}", "key", "value");
    27             var keys = valueProvider.GetKeysFromPrefix(string.Empty);
    28             foreach (var item in keys)
    29             {
    30                 Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
    31             }
    32 
    33             // Prefix="contact"
    34             Console.WriteLine("Prefix: contact");
    35             Console.WriteLine("{0,-14}{1}", "key", "value");
    36             keys = valueProvider.GetKeysFromPrefix("contact");
    37             foreach (var item in keys)
    38             {
    39                 Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
    40             }
    41 
    42             // Prefix="contact"
    43             Console.WriteLine("Prefix: contact.Address");
    44             Console.WriteLine("{0,-14}{1}", "key", "value");
    45             keys = valueProvider.GetKeysFromPrefix("contact.Address");
    46             foreach (var item in keys)
    47             {
    48                 Console.WriteLine("{0,-14}{1}", item.Key, item.Value);
    49             }
    50 
    51             Console.Read();
    52         }
    53     }
    54 }
  • 相关阅读:
    记录慕课学习爬取中国大学排名(由上交大计算的排名结果)
    SuperMap iMobile for Android室内导航APP
    Android studio入坑记录(SuperMap iMobile开发)
    2019年的十月和十一月
    python学习国庆期间
    学习python——collections系列
    又是快乐学习python的一天
    学习MATLAB
    Python学习练习题
    使用javaScript来实现一个有序链表
  • 原文地址:https://www.cnblogs.com/frankyou/p/4894253.html
Copyright © 2011-2022 走看看