Re: Reflection - When to use?

Tech-Archive recommends: Speed Up your PC by fixing your registry



"heddy" <hedbonker@xxxxxxxxx> a écrit dans le message de news:
1158438496.786252.154430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

|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?

For example, I write many different business classes, and I need to store
instance of these classes in a mechanism that hides the database and
translates those objects into SQL commands.

I write a storage mechanism with methods like this :

class Storage
{
void StoreObject(object obj)
{
PropertyInfo[] properties = obj.GetType().GetProperties();
// read properties and their values
// and create SQL Update or Insert statements
// using the names and values found.
}
...
}

and many other situations where the type of an object could be one of many.

However, reflection is not always necessary for these kind of tasks as the
Visitor design pattern can do this kind of thing

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer


.



Relevant Pages

  • Re: Reflection....
    ... > Can somebody point me to an explanation of what Reflection is? ... each class has metadata that describes the ... So that is the physical representation of the metadata. ... about the *called* type is added to the assembly of the calling type ...
    (microsoft.public.dotnet.general)
  • Re: get name of variable as string?
    ... Reflection by calling the Type.GetFieldsmethod. ... because their names are not compiled into the assembly's metadata. ... Well, it's just for debugging, so I may want to go there. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Was ist...?
    ... Damit kann man zu Laufzeit die Metadata abfragen ... > ein ActiveX Objekt zu verwenden die Typenbibliothek ... > Ist Reflection das gleiche wie der beschriebene Vorgang? ... Next by Date: ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Strong Names and LGPL
    ... metadata in the runtime; it is possible using them to write a tool that does ... in Whidbey there is probably going to be (or may be already in the Beta, ... so it should be possible to use the combination of Reflection ... and Reflection Emit to roundtrip an assembly and sign it then. ...
    (microsoft.public.dotnet.security)
  • Re: Meta-data on assemblies for CF...
    ... In the 1.1 version of the .NET Framework, custom attributes in the ... assembly and other metadata are not available via reflection. ... PEFile using the unmanaged MetaData API. ...
    (microsoft.public.dotnet.framework.compactframework)