Reputation: 35913
How can check whether a instance is marked as serializable?
Thanks
Upvotes: 1
Views: 232
Reputation: 60714
Since you are asking for instance, and not class, the correct answer is actually:
o.GetType().IsSerializable;
Upvotes: 3
Reputation: 22565
Type t = typeof(x)
for fields:
t.GetFields().Where(p=> !p.Attributes.HasFlag(FieldAttributes.NotSerialized));
for type
t.Attributes.HasFlag(TypeAttributes.Serializable);
Upvotes: 1
Reputation: 1089
have you tried?
o.GetType().FindInterfaces().Any(x => x == typeof(ISerializable));
Upvotes: 1