views:

62

answers:

2

I've been given a "for fun" challenge to write a "hello world" application. The only condition is that I use reflection, there is no specified way this condition must be met, but clever or elegant or "cool" uses are fun. Aside from injecting an external library or doing some sort of IHelloWorldMessageProvider composition container mojo, I don't see a lot of options. Someone care to enlighten me?

+1  A: 

The string "hello world" could be build dynamically at runtime by inspecting the class that implements your application. Say: class hello { void world() {} }

sblom
boring tho! more exciting?
Idahovandal256
+3  A: 

Personally, if I wanted to write a complex and interesting Hello World application using reflection...I would have to go with Dynamic Compilation. I don't have time to write a complete example, but the workflow would go something like:

  1. Start application.

  2. Create a string containing the Hello World C# code.

  3. Invoke the compiler from the application to create a DLL at runtime.

  4. Use Reflection to Load the generated assembly.

  5. Get the appropriate type and method...and then invoke it (thus showing the "Hello World" message).

Check out this page further explaining the process of dynamic compilation:

Executing Dynamic Code in .NET

Justin Niessner
Always fun. Would utlizing MEF be considered reflection? MEF operates using reflection so I don't see why not.
Idahovandal256