自定义键值列表

    创建键值列表,主要用于WCF动态传参。代码如下:

/// <summary>
    /// 键值列表
    /// </summary>
#if ! SILVERLIGHT
    [Serializable]
#endif
    public class StringPairList
    {
        public List<StringPair> SPList { get; set; }
 
        public StringPairList()
        {
            SPList = new List<StringPair>();
        }

        public string this[string p_key]
        {
            get
            {
                var item = SPList.FirstOrDefault(itm => itm.Key == p_key);
                if (item != null)
                {
                    return item.Value;
                }
                else
                {
                    return "";
                }
            }
            set
            {
                var item = SPList.FirstOrDefault(itm => itm.Key == p_key);
                if (item != null)
                {
                    item.Value = value;
                }
                else
                {
                    StringPair strPair = new StringPair();
                    strPair.Key = p_key;
                    strPair.Value = value;
                    SPList.Add(strPair);
                }
            }
        }

    }

赋值的代码如下:

            StringPairList spList = new StringPairList();
            spList["类别"] = "01";

取值的代码如下:

        public List<CVehicleInsurance> GetList(string p_Licence, StringPairList p_query)
        {
            string formType = p_query["类别"].ToString();   

        }

posted @ 2013-06-09 17:09  liuyunfeng  阅读(162)  评论(0编辑  收藏  举报