473,408 Members | 1,858 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,408 software developers and data experts.

Why is there no contains/exists in SerializationInfo?

I have been working with serialization in some places for a while and
have now begun to run into version issues.
Unfortunately my company is still working with .Net 1.1, so using the
VTS of 2.0 was not an option.
So I decided to have my classes implement ISerializable and wrote a
set of functions that use reflection and mimick version tolerant
serialization.
Unfortunately the only way to determine wether a field exists in a
SerializationInfo is to try to access it and catch the
SerializationException if it occurs.
Because of the nature of try/catching, this process can be rather slow
(especially when an old version is lacking many of the expected
fields), so I have been wondering why there is no way to determine
beforehand wether a certain field exists within a SerializationInfo.
I tried finding an answer on google, but to no avail, so I'm just
wondering wether any of you guys know?

Sincerely,
Kevin Wienhold

Mar 30 '07 #1
3 4760
After looking into the SerializationInfo class a bit more, I have
found a way to implement my own exists method, using the enumerator
supplied by GetEnumerator() to loop through the entries until I find
the one I want, however that still doesn't explain why this isn't
included in the class in the first place.

Mar 30 '07 #2
I agree, there should be some sort of method that will tell you if the
item exists for the current scope.

Using the GetEnumerator, you can eliminate the overhead of the
exceptions. However, I hope you are not calling GetEnumerator for each
member in your class, as this would most definitely cause a performance
problem as well.

Rather, instead of cycling through the members of your class using
reflection, why not call GetEnumerator and let that loop drive your process?
Then, you can call GetField on the Type instance of your class to see if the
field exists (and mark it if it doesn't). This way, you only have to loop
through the SerializationInfo once.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"KWienhold" <he******@trashmail.netwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
After looking into the SerializationInfo class a bit more, I have
found a way to implement my own exists method, using the enumerator
supplied by GetEnumerator() to loop through the entries until I find
the one I want, however that still doesn't explain why this isn't
included in the class in the first place.

Mar 30 '07 #3

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...
I agree, there should be some sort of method that will tell you if the
item exists for the current scope.

Using the GetEnumerator, you can eliminate the overhead of the
exceptions. However, I hope you are not calling GetEnumerator for each
member in your class, as this would most definitely cause a performance
problem as well.

Rather, instead of cycling through the members of your class using
reflection, why not call GetEnumerator and let that loop drive your
process? Then, you can call GetField on the Type instance of your class to
see if the field exists (and mark it if it doesn't). This way, you only
have to loop through the SerializationInfo once.
Or iterate once, storing into a Hashtable or Dictionary. Then you can use
the dictionary's own optimized Contains implementation.
>
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"KWienhold" <he******@trashmail.netwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>After looking into the SerializationInfo class a bit more, I have
found a way to implement my own exists method, using the enumerator
supplied by GetEnumerator() to loop through the entries until I find
the one I want, however that still doesn't explain why this isn't
included in the class in the first place.


Mar 31 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jay | last post by:
Hello, this probably isnt the best place to ask but I can't find a more suitable sql newsgroup so I hope y'all dont mind too much. I have 2 tables; Cellar and Colour CELLAR contains the wine...
6
by: Eric Robinson | last post by:
Hi all, I'm having real trouble wrapping my newbie brain around this problem. Can someone please tell me the most efficient (or any!) way to write a SELECT statement to return a set of rows from...
4
by: Robert W. | last post by:
I've built a complex collection object from "System.Collections.CollectionBase". With regard to it, I have a question about the "Contains" method. At first I thought that "Contains" would...
1
by: Erick T | last post by:
Hello, I am looking for a Web UI Control, either commercial or free. I don't know exactly what to call it, so I will describe what I need it to do. In a nutshell, it's a control to visually...
0
by: djc | last post by:
<snippet from .net documentation> If Panel1.Controls.Contains(NewPanelButton) Then RemoveHandler NewPanelButton.Click, AddressOf _ NewPanelButton_Click Panel1.Controls.Remove(NewPanelButton)...
1
by: Bob | last post by:
I'm creating my own Formatter, and I have this in the Serialize method to get ready to collect all the information I need: Dim c As New TestFormatterConverter Dim info As New...
0
by: ajay.kalyan | last post by:
I am trying to add an object to an arraylist, but first I need to see if the an object with a specified instance value already exists in the arraylist. The Contains(obj) function checks the entire...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
2
by: Jeff | last post by:
..NET 2.0 I'm trying to use List.Contains to determine if an object already exist in the list. This Contains method always return false in my code In my code a method gets a list of names, the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.