Custom attributes C#

DavidL davidl at 126.com
Wed Sep 26 21:05:24 PDT 2007


Sclytrack Wrote:

> Could D have custom attributes like in C# ?
> 
> public class MyCustomAttribute:Attribute
> {
>   public MyCustomAttribute( string text)
>   {
>    }
>   ...
> }
> 
> 
> class MyClass
> {
>   [MyCustom("my text")]
>   void DoStuff()
>   {
>   }
> }
> 
> The attributes can then be retrieved by system reflection. An attribute is
> a class thus can contain code.
> 
> 
> I was thinking of something similar in D, but simpler
> 
> attribute published;  // published would then be an attribute.
> 
> class Window
> {
>   attr(published) void caption(char [] text)
>   {
>   }
> }
> 
> __traits( allAttributes, )
> 
> 
> and maybe dropping the two underscores in the __traits
> 
> #d.lounge  Arthur, give Zuu a cookie.

I've proposed something about naming a scope. 
scope("myattribute")void caption(char [] text){}
there must be some more general thing. 
Maybe alias is a better naming

alias("myattribute") void caption(char[] text){}
alias("myvar") int var;





More information about the Digitalmars-d mailing list