473,224 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 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 2156
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: expertware | last post by:
Dear friends, When an object is cloned through serialization in memory, to make a copy. clearly the <NonSerialized> fields are not copied. To copy them I usually use (this is a very useful...
1
by: Timo | last post by:
When I use XML serialization to serialize a collection of MyObject, all of the public fields of the object are being serialized, even those I've given the <NonSerialized()> attribute. ...
3
by: Oren | last post by:
Hi everyone I just want to ask why this code below adds the variables i,v to the serialization too ? I have made them as NonSerialized I'm using XmlSerializer and TextWriter classes to create...
1
by: Alexander Muylaert | last post by:
How can I prevent an event of beng serialized? it always give me the error Attribute nonserialized is not valid on this declaration type ... Kind regards Alexander
5
by: Neil Norfolk | last post by:
I am using C# in Visual Studio 2003. I would like to serialize a class that contains, amongst other things, public delegate void DocumentsPreferencesChange(object env, Documents e); public event...
2
by: Crispin Horsfield | last post by:
It's not useful to serialize events in a class that can be serialized so in C# you can use the 'field' attribute to mark events as 'NonSerializable'.This is not available in VB. Does anyone know...
5
by: Samuel R. Neff | last post by:
Is there a way to add the NonSerialized attribute to the "Event" fields that the VB.NET compiler creates when you declare an event? I have a class that we use with binary serialization and we...
2
by: Timo | last post by:
When I use XML serialization to serialize MyCustomObjectCollection, all of the public fields of MyCustomObject are being serialized, even those I've given the <NonSerialized()> attribute. ...
2
by: greenxiar | last post by:
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.