Emulating Delegate.Target and Delegate.Method

  • Thread starter Thread starter rodrigobamboo
  • Start date Start date
R

rodrigobamboo

Hi,

We at db4objects[1] are working on the concept we call "Native
Queries"[2].

Our native queries implementation allows database queries to be
expressed in the same language the rest of the program is expressed,
for instance:

// Get all the customers from Brazil
IList<Customer> customers = db.Query<Customer>(delegate(Customer
c) {
return c.Address.Country == "Brazil";
});

The Query<T> method analyzes the bytecode of the received delegate
creating a query that can be effectively executed against the
underlying oodb engine.

When running on .net 2.0 framework we can simply use the
Delegate.Method property to get a hold of the method the delegate
points to and thus access its bytecode.

Unfortunately such a property is not available on the compact
framework.

The question is, would there be any way to get a hold of the MethodInfo
instance or method metadata token from the delegate instance?

Thanks for any help,
Rodrigo B. de Oliveira

PS: looking at the debugger we can see the _target and _methodPtr
fields but it has not occurred to us yet how to go from the _methodPtr
to the MethodInfo or method metadata token.

[1] http://www.db4o.com
[2]
http://www.db4o.com/about/productinformation/whitepapers/Native Queries Whitepaper.pdf
 
I'm afraid you can't retrieve MethodInfo of delegate instance. The
Method property uses FindMethodHandle function to get
RuntimeMethodHandle which is used for retrieving MethodInfo. But the
FindMethodHandle is not available in CF.NET 2.0.
 
Back
Top