.NET Core中的[Serializable]等效项是什么? (转换项目)

编程入门 行业动态 更新时间:2024-10-22 17:33:42
本文介绍了.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或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 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]等效项是什么? (转换项目)

本文发布于:2023-11-14 09:22:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586833.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   NET   Core   Serializable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!