Beispiel #1
0
        /// <summary>
        /// 从HTTP上下文的名称值对中装载数据到对象
        /// </summary>
        /// <typeparam name="T">T必须是一个类,而且必须带有无参构造函数</typeparam>
        /// <param name="pDataes">数据集</param>
        /// <param name="pSourceNames">源名称数组</param>
        /// <param name="pPropertyNames">对应的属性名称数组</param>
        /// <returns></returns>
        public static T LoadFrom <T>(NameValueCollection pDataes, string[] pSourceNames, string[] pPropertyNames) where T : class, new()
        {
            var mapping = new DictionaryPropertyNameMapping();

            if (pSourceNames != null && pSourceNames.Length > 0 &&
                pPropertyNames != null && pPropertyNames.Length > 0)
            {
                for (int i = 0; i < pSourceNames.Length && i < pPropertyNames.Length; i++)
                {
                    mapping.Add(pSourceNames[i], pPropertyNames[i]);
                }
            }
            //
            return(DataLoader.LoadFrom <T>(pDataes, mapping));
        }
Beispiel #2
0
        /// <summary>
        /// 从HTTP上下文的名称值对中装载数据到对象
        /// </summary>
        /// <typeparam name="T">T必须是一个类,而且必须带有无参构造函数</typeparam>
        /// <param name="pDataes">数据集</param>
        /// <param name="pMappings">源名称与属性名的映射字典,字典的KEY是源名称,字典的VALUE是属性名称</param>
        /// <param name="pInstance">T实例,如果实例为null则自动创建一个T实例</param>
        /// <returns></returns>
        public static T LoadFrom <T>(NameValueCollection pDataes, Dictionary <string, string> pMappings, T pInstance = null) where T : class, new()
        {
            var mapping = new DictionaryPropertyNameMapping(pMappings);

            return(DataLoader.LoadFrom <T>(pDataes, mapping, pInstance));
        }
Beispiel #3
0
        /// <summary>
        /// 从DataTable中装载数据
        /// </summary>
        /// <typeparam name="T">T必须是一个类,而且必须带有无参构造函数</typeparam>
        /// <param name="pDataes">数据集</param>
        /// <param name="pMappings">源名称与属性名的映射字典,字典的KEY是源名称,字典的VALUE是属性名称</param>
        /// <returns>T数组</returns>
        public static T[] LoadFrom <T>(DataTable pDataes, Dictionary <string, string> pMappings) where T : class, new()
        {
            var mapping = new DictionaryPropertyNameMapping(pMappings);

            return(DataLoader.LoadFrom <T>(pDataes, mapping));
        }