Custom attributes C#

Michel Fortin michel.fortin at michelf.com
Thu Sep 27 08:06:19 PDT 2007


On 2007-09-26 15:33:25 -0400, Sclytrack <sclytrack at pi.be> said:

> Could D have custom attributes like in C# ?

I'm all for it.

If done properly, this could allow me to simplify drastically the 
D/Objective-C bridge which is currently mimicking that with templates. 
It would make the syntax cleaner and could potentially make compilation 
much faster too.

In the bridge, I'm currently mimicking this with a mixin, for instance:

	class MyClass {
	
		void value(int v) { ... }
		mixin ObjcBindMethod!(value, void, "setValue:");
		
	}

This currently works by adding to the class a member struct I can later 
access using tupleof (D version 1 here). That struct only has static 
members so that it does not take up any space in object instance. These 
static members include the method definition for the Objective-C 
runtime with a pointer to a generated forwarder function.

Each method binding mixin has to repeat the function name, the return 
type and the type for all arguments, leaving only the Objective-C 
selector unrepeated. That's innefficient and somewhat error-prone.

With proper reflective attributes, things could be much cleaner.

Binding to Objective-C isn't much different from binding to a GUI, so 
surely this can benefit other senarios too.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list