• 以.net core重构原有.net framework过程中的一些API变更记录(持续更新)


    1)Type.IsGenericType类似属性变更

    以下是.net framework 4.5中Type抽象类中泛型类型的几个个属性,用于泛型类型的相关信息判断:

      

     以下是.net core(netstandard1.5)中Type抽象类中泛型类型的属性:

    可见Type类型中的IsGenericType(),IsGenericTypeDefinition()都被取消了,因此,如下.net framework 4.5.2中的代码:

        private static T ChangeType<T>(string value)
        {
            var t = typeof(T);
    
            // getting error here at t.IsGenericType
            if (t.IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
            {
                if (value == null)
                {
                    return default(T);
                }
    
                t = Nullable.GetUnderlyingType(t);
            }
    
            return (T)Convert.ChangeType(value, t);
        }

    在.net core(netstandard1.5)重构中只能以如下方式实现:

        private static T ChangeType<T>(string value)
        {
            var t = typeof(T);
    
            // changed t.IsGenericType to t.GetTypeInfo().IsGenericType
            if (t.GetTypeInfo().IsGenericType && t.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
            {
                if (value == null)
                {
                    return default(T);
                }
    
                t = Nullable.GetUnderlyingType(t);
            }
    
            return (T)Convert.ChangeType(value, t);
        }

    查看TypeInfo抽象类能看到如下抽象属性:

    同理,类似的还有类似IsValueType等属性的判断,都从Type抽象类中移到了TypeInfo抽象类中。

    2)Serializable特性变更

    根据其它帖子,该特性位置变更,可以导入如下程序集解决:

    解决方式:添加

    "System.Runtime.Serialization.Formatters": "4.0.0-rc3-24113-00"

    程序包

  • 相关阅读:
    linux环境变量
    linux make configure make
    摘自(http://www.ruanyifeng.com/blog/2011/07/linux_load_average_explained.html)
    linux eaccelerator
    linux du df ls
    linux phpize
    mysql 分页
    mysql 执行计划和慢日志记录
    mysql 添加/删除列(column)
    mysql 索引
  • 原文地址:https://www.cnblogs.com/you-you-111/p/6141019.html
Copyright © 2020-2023  润新知