Пример #1
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));
        }
Пример #2
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));
        }
Пример #3
0
 /// <summary>
 /// 从HTTP上下文的名称值对中装载数据到对象(属性映射采用键名与属性名的直接匹配)
 /// <remarks>
 /// <para>需要将名称值对中的值(string类型)转型为对象属性的类型,当前对象属性的类型只支持:</para>
 /// <para>1.string</para>
 /// <para>2.值类型(基础值类型+GUID+Enum)</para>
 /// <para>3.可空值类型</para>
 /// <para>如果不是以上类型,则会抛出转型无效的异常</para>
 /// </remarks>
 /// </summary>
 /// <typeparam name="T">T必须是一个类,而且必须带有无参构造函数</typeparam>
 /// <param name="pDataes">数据集</param>
 /// <param name="pInstance">T实例,如果实例为null则自动创建一个T实例</param>
 /// <returns></returns>
 public static T LoadFrom <T>(NameValueCollection pDataes, T pInstance = null) where T : class, new()
 {
     return(DataLoader.LoadFrom <T>(pDataes, new DirectPropertyNameMapping(), pInstance));
 }
Пример #4
0
 /// <summary>
 /// 从DataTable中装载数据(属性映射采用列名与属性名的直接匹配)
 /// </summary>
 /// <typeparam name="T">T必须是一个类,而且必须带有无参构造函数</typeparam>
 /// <param name="pDataes">数据集</param>
 /// <returns>T数组</returns>
 public static T[] LoadFrom <T>(DataTable pDataes) where T : class, new()
 {
     return(DataLoader.LoadFrom <T>(pDataes, new DirectPropertyNameMapping()));
 }