Right now I have a class that extends DynamicObject and overrides TryGetMember.
public class FieldCollection : DynamicObject, ICollection<Field>, ISerializable
{
...
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var field = _inner.TryGetField(binder.Name);
result = field == null ? null : field.Value;
return true;
}
...
}
dynamic fields = new FieldCollection();
Console.WriteLine(fields.Foo);
This works fine, but I'm forced to extend DynamicObject which means I can't extend anything else. Is it possible to do do this without extending DynamicObject?
You can implement IDynamicMetaObjectProvider yourself. It's a lot more work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With