XmlTextReader - how do I know the name of my variable

E

Ed Debrot

I am trying to write a simple serializer/deserializer for a set of
objects/classes that I have. When I deserialize I'd like to write the actual
variable name to my XML file but I don't know how to determine this at
run-time. I know the standard XmlSerializer must do this because it writes
the variable name and not the class.

Any ideas? I have a feeling there is a standard way to determine the
variable name but I have not idea. Something like

{
int x;

x.name();
}

or something similar.
 
A

Alex Feinman [MVP]

Variable name does not exist at run time. Fields and Peopreties do. Standard
serializer has no idea about the local variables either.
When you are serializing an object, typically you walk the list of the
fields or properties using reflection. Then you write to the output stream
the field name (FieldInfo.Name) and the field value (Field.GetValue() )
 
E

Ed Debrot

Ok, I'll look into this. But one more question. When you reference
Reflection, are you saying it is available in Compact Framework? I thought
it was not available in this environment.

thanks...
 
A

Alex Feinman [MVP]

Emit is not available. Some other advanced features like walking the stack
are not. But the simple stuff like RuntimeType and
Fields/Properties/Events/Constructors/Methods is there
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top