如何排除序列特定类型的?序列、类型

2023-09-04 11:20:55 作者:冷瞳里旳余温ァ

我跑 SGEN 对我组装一吨的类型。我要排除2种类型的序列化。我似乎并没有能够找到一种方法来做到这一点。

I run sgen against my assembly with a metric ton of types. I want to exclude 2 types from serialization. I don't seem to be able to find a way to do it.

我看到 SGEN 有一个 /类型开关来指定一个特定的类型,但没有排除特定的类型。

I see that sgen has a /type switch to specify a specific type, but nothing to exclude a specific type.

有没有办法从系列化排除特定类型的?

Is there a way to exclude specific types from serialization?

推荐答案

不知道如果你正在寻找这一点,但你可以通过提[非序列化]类定义之前排除你自己的类的序列化。 所以,如果你想排除特定的类型,你将不得不从它继承和创建自己的类

Not sure if you are looking for this but you can exclude your own classes from serialization by mentioning [NonSerialized] before class definition. So if you want to exclude a specific type you will have to inherit from it and create your own class

[NonSerialized]
public class Point
{
    public int x, y;
}