From: Tony Johansson on
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


From: Family Tree Mike on
On 5/4/2010 4:10 PM, Tony Johansson wrote:
> 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.

--
Mike
From: Arne Vajhøj on
On 04-05-2010 16:10, Tony Johansson wrote:
> 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
From: Arne Vajhøj on
On 04-05-2010 17:32, Family Tree Mike wrote:
> On 5/4/2010 4:10 PM, Tony Johansson wrote:
>> 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.
>
> 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