[Kde-bindings] Using Attributes on static methods in C# in Qyoto
Richard Dale
richard.j.dale at gmail.com
Sat Feb 3 22:12:15 UTC 2007
On Saturday 03 February 2007, Arno Rehn wrote:
> Am Freitag, 2. Februar 2007 schrieb Richard Dale:
> > I had planned on speeding up the lookup of methods in the Smoke library
> > from their 'munged method name', classname and arg type signatures, by
> > getting the munged name from the 'SmokeMethod' attribute like this:
> > [...]
> > So instead of deriving the munged name at runtime from the types of the
> > C# arguments, get it straight from the Attribute instance. Then when the
> > Smoke methodId has been found, cache it inside the Attribute rather than
> > maintaining a Hash.
>
> Good idea, makes the bindings probably a lot faster.
>
> > And it works fine with instance methods, but with static methods that
> > Attribute isn't retrieved. So this doesn't work for instance:
> > [...]
> > I was hoping there would be a special AttributeTargets flag for static
> > methods, but can't find one. I can't find any reference in the docs to
> > Attributes not working with static methods, so it's a bit frustrating..
>
> Hmm, that's funny. You should be able to apply attributes to static
> methods, too. Otherwise attributes like STAThread wouldn't work, as they
> are applied to the static Main() method.
It works fine now. The reason is that the transparent proxy for invoking
instance methods '_interceptor' is constructed from the the type of a class,
and so the methods annotated with 'SmokeMethod' in the class can be obtained
in SmokeInvocation.Invoke().
On the other hand, the transparent proxy for the static methods for a
class '_staticInterceptor' is constructed from an interface, and that
interface needs to have the individual method declarations annotated
with 'SmokeMethod'. The SmokeMethod Attribute has these
flags: 'Attributes.AttributeTargets.Interface' to allow it to be used in an
interface. The interface also needs to be annotated with a SmokeClass
attribute so that the c++ classname can be used for looking up methods in the
Smoke library.
-- Richard
More information about the Kde-bindings
mailing list