I was trying to figure out how to implement the method_missing method in C # 4, based on all 2 blog posts floating around on IDynamicObject.
What I want to do is to have a business logic level with a repository, and if this method is not at the business logic level, just call the repository and transfer its result. So, I have a class that looks like this:
public class CustomerServices : IDynamicObject { protected CustomerRepository _Repository = new CustomerRepository(); MetaObject IDynamicObject.GetMetaObject(Expression parameter) { return new RepositoryMetaObject<CustomerRepository>(_Repository, parameter); } }
In RepositoryMetaObect, I implement the Call method as follows:
public override MetaObject Call(CallAction action, MetaObject[] args) { typeof(T).GetMethod(action.Name).Invoke(_Repository, getParameterArray(args)); return this; }
(The rest of the RepositoryMetaObject code is probably not interesting, but I included it here: http://pastie.org/312842 )
The problem is, I think that I never do anything with the result of Invoke, I just return MetaObject.
Now when I do this:
dynamic service = new CustomerServices(); var myCustomer = service.GetByID(1);
GetByID is called, but if I try to access a property on myCustomer, it just hangs.
Can anybody help?
The full code can be downloaded ehre: https://dl.getdropbox.com/u/277640/BusinessLogicLayer.zip