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

查看:116
本文介绍了.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.

但是我想知道何时删除[可序列化]

But I want to know when I delete [Serializable]

什么是副作用?

应该更改哪些位置?

何时应使用JSON.NET(或...)代替[Serializable]吗?

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

推荐答案

如果您不序列化类型(tha t是,使用 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).

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

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天全站免登陆