Hi,
This might sound like a unusual question, but I would like to be able to
read a string from a XML stream and use this string at runtime to be able to
instantiate a 'new' object.
For example:
dim strObj as string = "ObjectA" 'This will be read from XML file
dim obj as new ObjectA 'Next time it could be ObjectB so I need to 'new
ObjectB'
Any help will be great.
Thanks in advance.
Regards. 4 1197
Sparmar2000 <Sp*********@discussions.microsoft.com> wrote: This might sound like a unusual question, but I would like to be able to read a string from a XML stream and use this string at runtime to be able to instantiate a 'new' object.
For example: dim strObj as string = "ObjectA" 'This will be read from XML file dim obj as new ObjectA 'Next time it could be ObjectB so I need to 'new ObjectB'
Have a look at Activator.CreateInstance and Type.GetType. You could
also use an XmlSerializer to make life easier for yourself :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon,
Thaks a lot for your quick response. I am familier with CreateInstance, and
also GetType, but can you please point me in the right direction with
XMLSerializer - perhaps with an example.
Thanks in advance.
Regards
Suresh
P.S. I will look on the web for example and papers on the subject as well as
soon as I have finished this post.
"Jon Skeet [C# MVP]" wrote: Sparmar2000 <Sp*********@discussions.microsoft.com> wrote: This might sound like a unusual question, but I would like to be able to read a string from a XML stream and use this string at runtime to be able to instantiate a 'new' object.
For example: dim strObj as string = "ObjectA" 'This will be read from XML file dim obj as new ObjectA 'Next time it could be ObjectB so I need to 'new ObjectB'
Have a look at Activator.CreateInstance and Type.GetType. You could also use an XmlSerializer to make life easier for yourself :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Sparmar2000 <Sp*********@discussions.microsoft.com> wrote: Thaks a lot for your quick response. I am familier with CreateInstance, and also GetType, but can you please point me in the right direction with XMLSerializer - perhaps with an example.
Well, the best thing to do is look in MSDN for an example. To be
honest, I hadn't used XmlSerializer before last week, but it seems to
be pretty easy to do. If you look at the examples in the XmlSerializer
constructor page, and the Serialize/Deserialize methods, it should make
it reasonably clear. Let me know if there's anything in particular you
don't understand.
P.S. I will look on the web for example and papers on the subject as well as soon as I have finished this post.
Goodo :)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon,
Just had a look at examples after searching the web - and you are right, it
seems pretty stright forward and clear.
Thanks a lot for your help.
Regards.
Suresh....
"Jon Skeet [C# MVP]" wrote: Sparmar2000 <Sp*********@discussions.microsoft.com> wrote: Thaks a lot for your quick response. I am familier with CreateInstance, and also GetType, but can you please point me in the right direction with XMLSerializer - perhaps with an example.
Well, the best thing to do is look in MSDN for an example. To be honest, I hadn't used XmlSerializer before last week, but it seems to be pretty easy to do. If you look at the examples in the XmlSerializer constructor page, and the Serialize/Deserialize methods, it should make it reasonably clear. Let me know if there's anything in particular you don't understand.
P.S. I will look on the web for example and papers on the subject as well as soon as I have finished this post.
Goodo :)
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
How dangerous or stupid is it for an object to have a reference to the
object which contains it? If I have a class called $controllerForAll
which has an arrray of all the objects that exist, what...
|
by: Ville Vainio |
last post by:
Pythonic Nirvana - towards a true Object Oriented Environment
=============================================================
IPython (by Francois Pinard) recently (next release - changes are...
|
by: Bijay Kumar |
last post by:
Hi Guys,
I was going through the source code of Object.cs in rotor. What I found is
Equals() implemented as follows:
public extern virtual bool Equals(Object obj);
What I don't...
|
by: Daniel |
last post by:
Hello =)
I have an object which contains a method that should execute every x ms. I
can use setInterval inside the object construct like this -
self.setInterval('ObjectName.methodName()',...
|
by: Nick Zdunic |
last post by:
I have a remotable object running in my host application.
The host starts up and creates the object. Within a method to start the
remote object doing its thing it creates an object.
...
|
by: Sparmar2000 |
last post by:
Hi,
This might sound like a unusual question, but I would like to be able to
read a string from a XML stream and use this string at runtime to be able to
instantiate a 'new' object.
For...
|
by: Bijay Kumar |
last post by:
Hi Guys,
I was going through the source code of Object class (Object.cs in rotor). What I found is
Equals() implemented as follows:
public extern virtual bool Equals(Object obj);
What...
|
by: yb |
last post by:
Hi,
Is there a standard for the global 'window' object in browsers? For
example, it supports methods such as setInterval and clearInterval, and
several others.
I know that w3c standardized...
|
by: User1014 |
last post by:
A global variable is really just a property of the "Global Object", so
what does that make a function defined in the global context? A method
of the Global Object?
...
|
by: Ralph |
last post by:
Hi
I don't understand why it's not working:
function schedule(imTop){
this.tdImagesTop = imTop;
}
schedule.prototype.selectEl = function() {
alert(this.tdImagesTop);
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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,...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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,...
| |