I don't use IronPython, so I may be completely wrong, but here is what I would suppose.
Given that Dynamic Language Runtime is now fully integrated in .NET 4.0 and IronPython is based on DLR, you should be able to use the standard .NET way of creating objects that handle setting/getting of non-existing members/attributes/properties. This can be done by implementing the IDynamicMetaObjectProvider
interface. A simpler way is to inherit from DynamicObject
, which provides default implementation for most of the methods and add only the method you need (see members of DynamicObject):
class MyObject : DynamicObject {
public override bool TryGetMember
(GetMemberBinder binder, out object result) {
string name = binder.Name;
// set the 'result' parameter to the result of the call
return // true to pretend that attribute called 'name' exists
}
public override bool TrySetMember
(SetMemberBinder binder, object value) {
// similar to 'TryGetMember'
}
}
In C# you can use this object thanks to dynamic
. IronPython should treat it in the same way!