Created
January 19, 2011 03:59
-
-
Save chrisnicola/785667 to your computer and use it in GitHub Desktop.
Some examples of how the dynamic keyword works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Fact] | |
public void cant_pass_base_class_to_function_dynamically() | |
{ | |
dynamic handler = new MessageHandler(); | |
IMessage message = new Message(); | |
handler.Handle(message); | |
} | |
[Fact] | |
public void can_pass_base_class_to_function_via_reflection() | |
{ | |
var handler = new MessageHandler(); | |
IMessage message = new Message(); | |
handler.GetType().GetMethod("DoSomething").Invoke(handler, new[] { message }); | |
} | |
[Fact] | |
public void can_pass_dynamic_type_to_funcation_dynamically() | |
{ | |
dynamic handler = new MessageHandler(); | |
dynamic message = new Message(); | |
handler.Handle(message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment