.NET Core 中 [Serializable] 的等价物是什么?(转换项目) [英] What is the equivalent of [Serializable] in .NET Core ? (Conversion Projects)

查看:27
本文介绍了.NET Core 中 [Serializable] 的等价物是什么?(转换项目)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多情况下,当我想将当前的 .NET Framework 项目转换为等效的 .NET Core 时,某些类具有 Serializable 属性.

In many cases, when I want to convert current .NET Framework projects to .NET Core equivalent, some classes have Serializable attribute.

我应该怎么做才能在 .NET Core 中转换它们?(这次我删了!!!)

What should I do for convert them in .NET Core ? (In this time I delete them !!!)

编辑

考虑这个代码:

using System;

namespace DotLiquid.Exceptions
{
    [Serializable] // I delete it now !!!!!!!
    public class FilterNotFoundException : Exception
    {
        public FilterNotFoundException(string message, FilterNotFoundException innerException)
            : base(message, innerException)
        {
        }

        public FilterNotFoundException(string message, params string[] args)
            : base(string.Format(message, args))
        {
        }

        public FilterNotFoundException(string message)
            : base(message)
        {
        }
    }
}

上面没有 [Serializable] 的代码在 .NET Core 中没有语法问题.

above code without [Serializable] works in .NET Core without syntax problem.

但是我想知道什么时候删除[Serializable]

But I want to know when I delete [Serializable]

什么是副作用?

应该改哪些地方?

我什么时候应该使用 JSON.NET(或 ...)而不是 [Serializable] ?

When should I use JSON.NET (or ...) instead of [Serializable] ?

推荐答案

如果你不序列化类型(即使用BinaryFormatter),那么你可以删除[Serializable] 忘记它.

If you aren't serializing the type (that is, using BinaryFormatter), then you can remove [Serializable] and forget about it.

如果您之前使用 BinaryFormatter 进行序列化,那么您需要制定自己的工作计划(即通过 Json.net 或 XML).

If you were using BinaryFormatter to serialize before, then you will need to come up with your own plan on how that will work (ie. via Json.net or XML).

如果您要移植一个库并代表您的消费者询问,那么答案是一样的:删除 [Serializable] 并将序列化留给需要它的人.

If you are porting a library and asking on behalf of your consumers then the answer is the same: remove [Serializable] and leave serialization up to those who need it.

这篇关于.NET Core 中 [Serializable] 的等价物是什么?(转换项目)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆