Inheritance: IDataProvider
Example #1
0
        /// <summary>
        /// 根据一个JSON来生成一个DataProvider
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public static IDataProvider ParseProvider(String json)
        {
            Dictionary<String, String> dict = JsonConvert.DeserializeObject<Dictionary<String, String>>(json);

            BasicDataProvider provider = new BasicDataProvider();

            if (dict != null && dict.Count > 0)
            {
                foreach (var pair in dict)
                {
                    provider.SetString(pair.Key, pair.Value);
                }
            }

            return provider;
        }
Example #2
0
        public static BasicDataProvider CreateFromJson(String json)
        {
            BasicDataProvider provider = new BasicDataProvider();
            Dictionary<String, String> dict = JsonConvert.DeserializeObject<Dictionary<String, String>>(json);
            foreach (var pair in dict)
            {
                provider.SetString(pair.Key, pair.Value);
            }

            return provider;
        }
Example #3
0
        public static BasicDataProvider CreateFromXml(String xml)
        {
            BasicDataProvider provider = new BasicDataProvider();

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlNodeList list = doc.SelectNodes(String.Format("/{0}/*", Constant.ParameterProviderNode));

            foreach (XmlNode node in list)
            {
                String name = node.Name;
                String val = node.InnerText.Trim();

                Int32 valInt;
                if (Int32.TryParse(val, out valInt))
                {
                    provider.SetInt(name, valInt);
                }
                else
                {
                    provider.SetString(name, val);
                }
            }

            return provider;
        }