简体   繁体   中英

C#: How to check whether a instance is serializable

How can check whether a instance is marked as serializable?

Thanks

typeof(MyClass).IsSerializable;

由于您要求的是实例而非类,因此正确的答案实际上是:

o.GetType().IsSerializable;

你有没有尝试过?

o.GetType().FindInterfaces().Any(x => x == typeof(ISerializable));
        Type t = typeof(x) 
        for fields:
        t.GetFields().Where(p=> !p.Attributes.HasFlag(FieldAttributes.NotSerialized));
        for type
        t.Attributes.HasFlag(TypeAttributes.Serializable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM