473,513 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML De-serializing and Events

Two questions really:

1. Can an object de-serialise itself?

I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the
new object to the caller.

<code>
Dim serializer As New XmlSerializer(GetType(MyType))

fs = New FileStream(filename, FileMode.Open)

return CType(serializer.Deserialize(fs), MyType)
</code>

I would prefer to create a new object of type MyType and then call a method
of MyType to de-serialise it. Is this possible?

2. Is there an event that is raised when de-serialisation is complete?

In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I
can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called
automatically?

TIA

Charles
Nov 20 '05 #1
4 1464
In article <Oe**************@TK2MSFTNGP09.phx.gbl>, bl***@nowhere.com
says...
Two questions really:

1. Can an object de-serialise itself?

I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the
new object to the caller.

<code>
Dim serializer As New XmlSerializer(GetType(MyType))

fs = New FileStream(filename, FileMode.Open)

return CType(serializer.Deserialize(fs), MyType)
</code>

I would prefer to create a new object of type MyType and then call a method
of MyType to de-serialise it. Is this possible?
You could make a shared (static) member of MyType that will do the same
thing your code is doing:

Public Shared Function DeSer(filename as String) As MyType
Dim serializer As New XmlSerializer(GetType(MyType))
fs = New FileStream(filename, FileMode.Open)
return CType(serializer.Deserialize(fs), MyType)
End Sub

Now you can do:

dim data As MyType = MyType.DeSer("C:\abc\123.xml")
2. Is there an event that is raised when de-serialisation is complete?

In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I
can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called
automatically?


I believe deserialization is synchronous so no other code will execute
until the deserialization is complete.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
In article <Oe**************@TK2MSFTNGP09.phx.gbl>, bl***@nowhere.com
says...
Two questions really:

1. Can an object de-serialise itself?

I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the
new object to the caller.

<code>
Dim serializer As New XmlSerializer(GetType(MyType))

fs = New FileStream(filename, FileMode.Open)

return CType(serializer.Deserialize(fs), MyType)
</code>

I would prefer to create a new object of type MyType and then call a method
of MyType to de-serialise it. Is this possible?
You could make a shared (static) member of MyType that will do the same
thing your code is doing:

Public Shared Function DeSer(filename as String) As MyType
Dim serializer As New XmlSerializer(GetType(MyType))
fs = New FileStream(filename, FileMode.Open)
return CType(serializer.Deserialize(fs), MyType)
End Sub

Now you can do:

dim data As MyType = MyType.DeSer("C:\abc\123.xml")
2. Is there an event that is raised when de-serialisation is complete?

In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I
can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called
automatically?


I believe deserialization is synchronous so no other code will execute
until the deserialization is complete.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #3
Hi Patrick

Thanks for the answers. The former is exactly the type of thing I was hoping
for.

With regard to the latter, it wasn't so much the synchronicity of the
process that was troubling me. It was the fact that a user of my class would
have to remember to call its Initialise method after de-serialising.
However, your answer to the first question obviates that as I can now make
it part of the shared method, so thanks again.

Charles
"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <Oe**************@TK2MSFTNGP09.phx.gbl>, bl***@nowhere.com
says...
Two questions really:

1. Can an object de-serialise itself?

I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the new object to the caller.

<code>
Dim serializer As New XmlSerializer(GetType(MyType))

fs = New FileStream(filename, FileMode.Open)

return CType(serializer.Deserialize(fs), MyType)
</code>

I would prefer to create a new object of type MyType and then call a method of MyType to de-serialise it. Is this possible?


You could make a shared (static) member of MyType that will do the same
thing your code is doing:

Public Shared Function DeSer(filename as String) As MyType
Dim serializer As New XmlSerializer(GetType(MyType))
fs = New FileStream(filename, FileMode.Open)
return CType(serializer.Deserialize(fs), MyType)
End Sub

Now you can do:

dim data As MyType = MyType.DeSer("C:\abc\123.xml")
2. Is there an event that is raised when de-serialisation is complete?

In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called automatically?


I believe deserialization is synchronous so no other code will execute
until the deserialization is complete.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 20 '05 #4
Hi Patrick

Thanks for the answers. The former is exactly the type of thing I was hoping
for.

With regard to the latter, it wasn't so much the synchronicity of the
process that was troubling me. It was the fact that a user of my class would
have to remember to call its Initialise method after de-serialising.
However, your answer to the first question obviates that as I can now make
it part of the shared method, so thanks again.

Charles
"Patrick Steele [MVP]" <pa*****@mvps.org> wrote in message
news:MP************************@msnews.microsoft.c om...
In article <Oe**************@TK2MSFTNGP09.phx.gbl>, bl***@nowhere.com
says...
Two questions really:

1. Can an object de-serialise itself?

I use XMLSerializer and the Deserialize method to read an XML file and
return an object of my given type. The code that does this then returns the new object to the caller.

<code>
Dim serializer As New XmlSerializer(GetType(MyType))

fs = New FileStream(filename, FileMode.Open)

return CType(serializer.Deserialize(fs), MyType)
</code>

I would prefer to create a new object of type MyType and then call a method of MyType to de-serialise it. Is this possible?


You could make a shared (static) member of MyType that will do the same
thing your code is doing:

Public Shared Function DeSer(filename as String) As MyType
Dim serializer As New XmlSerializer(GetType(MyType))
fs = New FileStream(filename, FileMode.Open)
return CType(serializer.Deserialize(fs), MyType)
End Sub

Now you can do:

dim data As MyType = MyType.DeSer("C:\abc\123.xml")
2. Is there an event that is raised when de-serialisation is complete?

In the above scenario, I need to perform some initialisation of the new
MyType object, but after it has been de-serialised. Is there an event that I can handle that is raised when de-serialisation is complete, or, better
still, is there a method that I can implement in MyType that will get called automatically?


I believe deserialization is synchronous so no other code will execute
until the deserialization is complete.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 20 '05 #5

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

Similar topics

2
3013
by: grigoo | last post by:
bonjour a tous je me presente a vous::: greg dit le grigoo sur le web ,,etudiant en bioinformatique a montreal et jusqu au cou dans notre language prefere....java. et biojava.. et je suis en un...
0
1715
by: Laurent Pointal | last post by:
Bienvenue sur la liste Python francophone, hébergée par l'AFUL, ou sur le newsgroup fr.comp.lang.python ("fclp"). Votre abonnement à cette liste de diffusion ou votre lecture de fclp montrent...
0
463
by: Michael Dyson | last post by:
M. Michael DYSON DIRECTEUR-ADJOINT SOCIÉTÉ DE SÉCURITÉ SARL. TEL.00229 20 21 80 Cotonou République du Bénin Email:michaeldyson2005@latinmail.com Bonjour . Je sais que mon message sera d’une...
0
2218
by: Alejandro Scomparin | last post by:
FORMULACION, PREPARACION Y EVALUACION ECONOMICA Y FINANCIERA DE PROYECTOS DE TECNOLOGIA INFORMATICA (IT) en la UTN Inicia: 17 de Mayo. 19 hs Dirigido a Esta preparado para gerentes, jefes,...
0
4278
by: Alejandro Scomparin | last post by:
FORMULACION, PREPARACION Y EVALUACION ECONOMICA Y FINANCIERA DE PROYECTOS DE TECNOLOGIA INFORMATICA (IT) en la UTN Inicia: 17 de Mayo. 19 hs Dirigido a Esta preparado para gerentes, jefes,...
0
1472
by: gandalf | last post by:
Con motivo del enorme esfuerzo realizado para visitar la ciudad argentina de Córdoba, participar en la Reunión del MERCOSUR, en la clausura de la Cumbre de los Pueblos en la histórica Universidad...
1
1612
by: crow | last post by:
http://www.pagina12.com.ar/diario/elpais/1-72984-2006-09-14.html Por Miguel Bonasso Desde La Habana Me había preparado para verlo, pero la realidad fue mucho más fuerte. Incluso le llevaba de...
1
1503
by: gandalf | last post by:
CON LA PASION DE SIEMPRE HABLO DE CHAVEZ, DE LA MEDICINA CUBANA... Y DE SU PROPIA MUERTE Relato de la nueva gran batalla de Fidel El líder cubano mostró cómo evoluciona su recuperación en el...
1
1616
by: Sebastien | last post by:
Bonjour, Je tient d'abort a m'excuser de poster cette demande ici, mais je ne vois pas tres bien ou fair cette demande, Je développe un logiciel de génération de code (Génération de Code VB et...
0
7264
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7166
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
7386
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
7534
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
5689
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,...
1
5094
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
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.