[Kde-bindings] Using Attributes on static methods in C# in Qyoto

Richard Dale richard.j.dale at gmail.com
Sat Feb 3 22:52:25 UTC 2007


On Saturday 03 February 2007, Arno Rehn wrote:
> > 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 was because the transparent proxy for calling static methods was
constructed from an interface, whereas the transparent proxy for
instance methods was constructed from the type of a class. So a
'SmokeMethod' Attribute needed to be added to the method declaration
for the interface of static method calls with these flags:

AttributeTargets.Constructor
| AttributeTargets.Method
| AttributeTargets.InterfaceFor example:

The interface for constructing a transparent proxy for static method
calls needed to be annotated like this:

[SmokeClass("QWidget")]
interface IQWidgetProxy {
    [SmokeMethod("tr", "(const char*, const char*)", "$$")]
    string Tr(string s, string c);
    ...

-- Richard



More information about the Kde-bindings mailing list