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

Richard Dale rdale at foton.es
Fri Feb 2 20:05:01 UTC 2007


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:

[SmokeMethod("notify##", "(QObject*, QEvent*)")]
public virtual bool Notify(QObject arg1, QEvent arg2) {
    return ProxyQCoreApplication().Notify(arg1,arg2);
}

An extra munged name arg was added the the SmokeMethod class:

	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method, 
					AllowMultiple=true)]
	class SmokeMethod : Attribute
	{
		public string mungedName;
		public string signature;
		public int methodId = -1;

		public string MungedName
		{
			get
			{
				return mungedName;
			}
		}
	
		public string Signature
		{
			get
			{
				return signature;
			}
		}
	
		public SmokeMethod(string mungedName, string signature)
		{
			this.mungedName = mungedName;
			this.signature = signature;
		}
	}

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.

And it works fine with instance methods, but with static methods that 
Attribute isn't retrieved. So this doesn't work for instance:

[SmokeMethod("sessionBus", "()")]
public static QDBusConnection SessionBus() {
    return StaticQDBusConnection().SessionBus();
}

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..

-- Richard



More information about the Kde-bindings mailing list