NonSerialized!

G

greenxiar

Hi,

When i enumerate fields in class with reflection,
How to know if a field is marked as NonSerialized?

Type c2 = typeof(Class2);
foreach(FieldInfo m in c2.GetFields
(BindingFlags.NonPublic|
BindingFlags.Instance|
BindingFlags.GetField|
BindingFlags.SetField)) {
Console.WriteLine(m);
if (Attribute.IsDefined(m, typeof(NonSerializedAttribute)))
Console.WriteLine(": is NonSerialized Field!");
}

IsDefined, GetCustomAttributes, GetCustomAttribute seems can
not detect the NonSerializedAttribute!

Green Xiar
 
G

Guest

If I recall correctly there is a IsNotSerialized property on FieldInfo.

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top