Using Reflextion

T

Tony Johansson

Hi!

I have only seen some artificial example of how reflection can be used.
Is it anyone that have any good example of when it's good to have this
reflection.

//Tony
 
F

Family Tree Mike

Hi!

I have only seen some artificial example of how reflection can be used.
Is it anyone that have any good example of when it's good to have this
reflection.

//Tony

I'm pretty sure that I have read XmlSerialization works via reflection.
This is why the serialized class is required to have a public
parameterless constructor and properties that can be set. The
serializer can get the class name from the element and the properties to
set via the attributes and child elements. Reflection also gives access
to attributes on the properties to control the
serialization/deserialization process.

Without reflection, I believe we would need to be writing custom
serializers.
 
A

Arne Vajhøj

I have only seen some artificial example of how reflection can be used.
Is it anyone that have any good example of when it's good to have this
reflection.

You could write your own little persistence framework that
can save any object to a database by using classname as
tablename and all properties as fields.

Besides persistence stuff then IoC stuff and AOP stuff also
usually use reflection.

Arne
 
A

Arne Vajhøj

I'm pretty sure that I have read XmlSerialization works via reflection.
This is why the serialized class is required to have a public
parameterless constructor and properties that can be set. The serializer
can get the class name from the element and the properties to set via
the attributes and child elements. Reflection also gives access to
attributes on the properties to control the
serialization/deserialization process.

The way XmlSerializer works requires a no-arg constructor.

But in general reflection is possible also with classes that does
not have a no-arg constructor.

Arne
 

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