Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I implement method_missing in C# 4 and have it actually return a value?
    primarykey
    data
    text
    <p>I was trying to figure out how to implement method_missing in C# 4, based on all of 2 blog posts floating around on IDynamicObject. </p> <p>What I want to do is have a Business Logic Layer that has a Repository, and if the method is missing from the Business Logic Layer, just call the Repository and pass through its result. So i have a class that looks like this:</p> <pre><code>public class CustomerServices : IDynamicObject { protected CustomerRepository _Repository = new CustomerRepository(); MetaObject IDynamicObject.GetMetaObject(Expression parameter) { return new RepositoryMetaObject&lt;CustomerRepository&gt;(_Repository, parameter); } } </code></pre> <p>In RepositoryMetaObect I implement the Call method like so:</p> <pre><code> public override MetaObject Call(CallAction action, MetaObject[] args) { typeof(T).GetMethod(action.Name).Invoke(_Repository, getParameterArray(args)); return this; } </code></pre> <p>(The rest of RepositoryMetaObject code probably isn't interesting, but I've included it here: <a href="http://pastie.org/312842" rel="nofollow noreferrer">http://pastie.org/312842</a>)</p> <p>The problem I think is that I'm never doing anything with the result of the Invoke, I'm just returning the MetaObject itself. </p> <p>Now when I do this:</p> <pre><code> dynamic service = new CustomerServices(); var myCustomer = service.GetByID(1); </code></pre> <p>GetByID is called, but if I try to access a property on myCustomer, is just hangs. </p> <p>Can anyone please help?</p> <p>Complete code can be downloaded ehre: <a href="https://dl.getdropbox.com/u/277640/BusinessLogicLayer.zip" rel="nofollow noreferrer">https://dl.getdropbox.com/u/277640/BusinessLogicLayer.zip</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload