471,339 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

NonSerialized!

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
Aug 9 '05 #1
2 2073
FieldInfo has IsNotSerialized property!

"greenxiar" <gr*******@hotmail.com> дϢ
news:#y**************@TK2MSFTNGP10.phx.gbl...
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

Aug 9 '05 #2
If I recall correctly there is a IsNotSerialized property on FieldInfo.

Hope this helps

--
Brian Delahunty
Ireland

http://briandela.com/blog
"greenxiar" wrote:
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

Aug 9 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Timo | last post: by
3 posts views Thread by Oren | last post: by
5 posts views Thread by Neil Norfolk | last post: by
2 posts views Thread by Crispin Horsfield | last post: by
2 posts views Thread by greenxiar | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.