zoukankan      html  css  js  c++  java
  • paip.使用泛型时未能找到类型或命名空间名称“T

    paip.使用泛型时未能找到类型或命名空间名称“T

    使用泛型参数时,方法也需要加<T>标签...

     public void bindList2grid<T>(List<T> li, DataTable dt)
            {
                
                foreach (T tc in li)
                {
                      DataRow dr=     bindObj2Row(tc,dt);
                      dt.Rows.Add(dr);
                }
            
            }

     //反回值为范型
            public static T getValue<T>(object entity, string fieldName)
            {
                Type entityType = entity.GetType();
                PropertyInfo propertyInfo = entityType.GetProperty(fieldName);
                if (propertyInfo == null)
                    return default(T);
                if (IsType(propertyInfo.PropertyType, "System.String"))
                {
                    return (T)propertyInfo.GetValue(fieldName, null);

                }
                return default(T);
        
                //if (IsType(propertyInfo.PropertyType, "System.String"))
                //{
                //    propertyInfo.SetValue(entity, fieldValue, null);
            }

  • 相关阅读:
    在线工具TOOL收藏
    HtmlDocument [代码碎片笔记]
    ChromiumWebBrowser [链接]
    PHP [开发汇总]
    Discuz[技术文献]
    [jvm] -- 监控和调优常用命令工具篇
    [jvm] -- 常用内存参数配置篇
    [日常摘要] -- 事务的隔离级别篇
    [日常摘要] -- ThreadLocal篇
    [日常摘要] -- zookeeper篇
  • 原文地址:https://www.cnblogs.com/attilax/p/15199937.html
Copyright © 2011-2022 走看看