Quantcast
Channel: jolt Forum Rss Feed
Viewing all articles
Browse latest Browse all 7

New Post: Honouring Implemented Interfaces

$
0
0

Hello angolon!
Thank you for posting your question with your feedback.
Coincidentally, I was thinking about this very problem a few weeks ago while implementing the circular collections that were committed last week.  It turns out that I need this very feature to cleanly implement a collection adaptor, but in its absence resorted to creating the adaptor manually.
I've reviewed my notes on the issue and believe I have a solution, which follows this algorithm.
  • Add a new method to the ProxyTypeBuilder class that accepts an interface that the resulting proxy/interface pair will implement
    • It must be a valid interface that is specified on the real subject type
    • ProxyAssemblyBuilder will call this method for each interface implemented by the real subject type
  • For each method on the given interface, add an approriate forwarding method on the generated proxy type
    • We use Type.GetInterfaceMap() and InterfaceMap.TargetMethods to find the method that the proxy needs to forward to
    • If the method is already present, emit a warning and ignore it
  • Compile proxy and interface types
    • Any problems will be due to the caller adding ambiguous methods; though if the algorithm is specific in detecting duplicate methods, I can't see how this will ever happen.

This is a pretty straightforward solution that should work, supporting both generic and implictly/explicitly implemented methods.  Do let me know what you think of this approach!

On a side note, I've since reviewed my blog post that initially described the complexity of this problem and now realize I got it all wrong.  I was intending on adding all the required interfaces to the proxy first, then trying to match methods given by users with those that the interfaces require.  This approach doesn't make much sense now, since it is possible for the generated type to be in an incosistent state (i.e. missing method implementations).
In the mean time, I've moved the work item into the next release bucket, but can't say when it will be completed and tested.  Hopefully I can get to it in February.

Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>