If I am the sole author of an application, I already know the metadata
about my classes - I wrote them. And even if I did not - Let's say I
buy a 3rd party class lib, it will be documented for me with that lib.
If that's all you have, you won't likely need to deal with reflection in
your scenario.
Here's a common scenario. What if you decided that you wanted to open up
your application to others by offering a plug-in architecture. Your
application then loads in these third party plug-ins at runtime and executes
functions that you previously defined. Reflection would be used to evaluate
the type and member definitions of these plug-ins to determine compatibility
and to invoke the appropriate members at the appropriate times.
Another common scenario is manual serialization. Let's say that you wanted
to provide a class library that could take someone else's objects, serialize
them, transport them to another computer, and then deserialize them, even if
the objects were not marked as serializeable. You could use reflection to
deconstruct these objects, capture the values using preevaluated type
information that was understood using reflection, then reconstruct the
objects, possibly using System.Reflection.Emit.
Generally, .NET reflection is a handy feature that allows you to introspect
the assembly, type, and member information of any .NET solution (including
your own), or to construct new classes at runtime using Emit. However, you
asked a good question in that you should not care about reflection unless
you need it. It should never be used for loose typing, for example, when
strongly typed solutions can be accomplished just as easily, because
strongly typed solutions have better performance and are typically far more
stable and secure.
Jon
"heddy" <he*******@gmail.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>I understand that reflection allows me to discover the metadata of a
class at runtime (properties, methods etc). What I don't understand is
where this is useful. For example:
If I am the sole author of an application, I already know the metadata
about my classes - I wrote them. And even if I did not - Let's say I
buy a 3rd party class lib, it will be documented for me with that lib.
If I am part of a dev team, the same is true - If I use a class that I
did not author, I should still be able to reference the documentation
for that class and use it.
Can someone clarify for me?