I am trying to get a simple DynamicObject example working in .NET 3.5.
Using the latest assembly of the DLL with the code, I could not figure out what is equivalent to .NET 3.5 as follows:
public class DynamicObjectBag : DynamicObject
{
private Dictionary<string, object> _properties = new Dictionary<string, object>();
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
return _properties.TryGetValue(binder.Name, out result);
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_properties[binder.Name] = value;
return true;
}
}
dynamic foo = new DynamicObjectBag();
foo.Val1 = 3;
foo.Val2 = "Value 2";
This, of course, is a simplified example. I plan to derive classes from DynamicObject, so I can use both direct object properties and properties stored in the dictionary using the same notation or access methods to the semantic point. The goal is to have DLR-compatible objects for use in languages ββthat support DLR and to ensure future compatibility with .NET DLR features when an application can be upgraded to .NET 4.0.
, pre -.NET 4.0 . , TryGetMember, , GetMemberBinder. .NET 4.0 #, , , .NET 3.5.
, , , #.NET 4.0 .
, , DynamicObject .NET 3.5 .. .
:
http://tomlev2.wordpress.com/2009/10/08/c-4-0-implementing-a-custom-dynamic-object/