[nem-en] Finding an interface method implementation.
Michal Moskal
malekith at pld-linux.org
Mon Sep 27 14:56:43 CEST 2004
On Mon, Sep 27, 2004 at 02:03:22PM +0200, Kamil Skalski wrote:
> Dnia poniedziałek, 27 września 2004 13:13, Daniel James napisał:
> > I'm trying to write a macro to automatically dispose of a field. For a
> > class like this:
>
> Nice idea, let take a look how to do it.
>
> > class Foo : System.IDisposable
> > {
> > [Utility.AutoDispose]
> > bar : Bar;
> >
> > private MyDispose() : void
> > implements System.IDisposable.Dispose
> > {
> > }
> > }
>
> The macro should be in WithTypedMembers phase and perform something like:
>
> macro AutoDispose (t : TypeBuilder, f : FieldBuilder) {
[...]
> I'm not sure if this is the best and most efficient way to do this, but
> current implementaion of compiler seems to do such things from time to time.
> Maybe Michal can come out with some nicer way to do this.
This one should work, but it would be probably better to do
Nemerle reflection on System.IDisposable and look for method there. It
also has a proper Equals method, something along the lines of:
def method = {
def tc = GlobalEnv.LookupInternalType ("System.IDisposable");
match (tc.LookupMember ("Dispose")) {
| [x] => x
| _ => assert (false)
}
}
...
List.Filter (implemented, fun (im) {
im.Equals (method)
...
But this is probably more like style issue. It would be better to do
that this way, if it was about some method of interface defined in
current compilation unit.
> Probably we should add a special API make it easier. We will take your
> question as a vote, that this particular API would be nice to have.
> Any suggestions are welcomed - currently API is created when needed and when
> somebody has some nice idea for useful methods.
Something like:
Tycon.MethodImplementing (meth : IMethod) : option <IMethod>
?
--
: Michal Moskal :: http://www.kernel.pl/~malekith :: GCS !tv h e>+++ b++
: When in doubt, use brute force. -- Ken Thompson :: UL++++$ C++ E--- a?
More information about the devel-en
mailing list