Skip to content

Instantly share code, notes, and snippets.

@svick
Created April 24, 2011 11:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svick/939505 to your computer and use it in GitHub Desktop.
Save svick/939505 to your computer and use it in GitHub Desktop.
DynamicObject
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