zoukankan      html  css  js  c++  java
  • 以.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"

    程序包

  • 相关阅读:
    怎样设置HTML上传控件,上传文件的大小
    在winform里怎么调用WebBrowser控件里的脚本
    可输入的DropDownList控件
    javascript + DIV +CSS 实现可拖动消息窗体
    又是一周的开始
    document.execCommand() 解析
    怎样将DataGrid的列值统计并显示在页脚
    如何添加在线QQ咨询?
    徐普~~~~个性语言堪称经典~~~~
    软键盘的实现
  • 原文地址:https://www.cnblogs.com/you-you-111/p/6141019.html
Copyright © 2011-2022 走看看