Created
April 24, 2011 11:45
-
-
Save svick/939505 to your computer and use it in GitHub Desktop.
DynamicObject
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
using System; | |
using System.Dynamic; | |
namespace ConsoleApplication1 | |
{ | |
class Dynamic : DynamicObject | |
{ | |
public override bool TryGetMember(GetMemberBinder binder, out object result) | |
{ | |
if (binder.Name == "Name") | |
{ | |
result = "Svick"; | |
return true; | |
} | |
return base.TryGetMember(binder, out result); | |
} | |
} | |
class Program | |
{ | |
static void Main() | |
{ | |
dynamic dynamic = new Dynamic(); | |
Console.WriteLine(dynamic.Name); // writes "Svick" | |
var dict = new System.Web.Routing.RouteValueDictionary(dynamic); | |
Console.WriteLine(dict.Count); // writes "0" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment