在许多情况下,当我要将当前的.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]等效项是什么? (转换项目)
发布评论