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?
views:
62answers:
2
+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
2010-08-12 04:50:06
boring tho! more exciting?
Idahovandal256
2010-08-12 04:53:32
+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:
Start application.
Create a string containing the Hello World C# code.
Invoke the compiler from the application to create a DLL at runtime.
Use Reflection to Load the generated assembly.
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:
Justin Niessner
2010-08-12 05:00:18
Always fun. Would utlizing MEF be considered reflection? MEF operates using reflection so I don't see why not.
Idahovandal256
2010-08-12 17:20:11