zoukankan      html  css  js  c++  java
  • 泛型摘录

    一段类型转化

    --------------------------------------------------------------------

     /// <summary>
                /// Gets the value.
                /// </summary>
                /// <typeparam name="T"></typeparam>
                /// <param name="columnName">Name of the column.</param>
                /// <returns></returns>
                public T GetValue<T>(string columnName)
                {
                    columnName = columnName.ToLowerInvariant();
                    object oVal;

                    try
                    {
                        oVal = this[columnName].CurrentValue;
                    }
                    catch
                    {
                        throw new ArgumentException("There's no column called '" + columnName + "' for this object", "columnName");
                    }

                    if(oVal == null || oVal == DBNull.Value)
                        return default(T);

                    Type type = typeof(T);

                    if(type == typeof(object))
                        return (T)oVal;

                    // handle nullable type conversion
                    if(IsNullable(type))
                    {
                        NullableConverter converter = new NullableConverter(type);
                        type = converter.UnderlyingType;
                    }

                    //if (IsNullable(type) || type == typeof(object))
                    //{
                    //    if (type == typeof(bool?))
                    //        return (T)(object)Convert.ToBoolean(oVal);
                    //    return (T)oVal;
                    //}

                    //if (type == typeof(Guid))
                    //    return (T)(object)new Guid(oVal.ToString());

                    Type valType = oVal.GetType();
                    if(valType == typeof(Byte[]))
                        return (T)Convert.ChangeType(oVal, valType);

                    return (T)Convert.ChangeType(oVal, type);
                }

  • 相关阅读:
    R语言ENTREZID ID 转换 gene SYMBOL
    annvar下载数据库的网址
    R语言实现定性资料的秩和检验
    如何获得FPKM/RPKM计算需要的基因长度(考虑exon之间的overlap)
    linux和windows中文显示乱码问题
    从一篇nature medicine文章的得到的可用于文献画图的19种16进制颜色码
    简单将ggplot多个图排列在一起
    python通用读取vcf文件的类(可以直接复制粘贴使用)
    ROCR包中ROC曲线计算是取大于cutoff还是大于等于cutoff
    tinyproxy 反向代理无法上网原因
  • 原文地址:https://www.cnblogs.com/wdfrog/p/1749713.html
Copyright © 2011-2022 走看看