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 4 1457
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |