Using Reflextion

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
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
 
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.
 
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
 
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
 
Back
Top