Wiki

Changes between Version 2 and Version 3 of Attributes

Show
Ignore:
Timestamp:
01/28/13 07:54:38 (11 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Attributes

    v2 v3  
    1 == Attributes == 
    2 Cobra has the same type of declarations of attributes just like C# but without square brackets and using the has keyword before the attribute 
    3 You also declare the attribute after declaring the variable. 
     1= Attributes = 
    42 
    5 You can add attributes to classes and functions and variables also properties e.g. In GTK 
     3Attributes are items of metadata appended to specific program items that end up supplied with your program.[[BR]] 
     4 
     5Some of these are given as of standard (Types and Members).[[BR]] 
     6 
     7User defined or Custom attributes can be declared and given to specify additional information required or desired.[[BR]] 
     8 
     9These attributes provided can be then queried by standard or additional tools or by runtime examination (reflection). 
     10 
     11Cobra provides for the declaration and use of attributes similarly to  C# ( on .Net) and Java Language (on Jvm). 
     12These are declared using a keyword prefix ('''has''') with the Attribute (or comma separated Attributes) following  
     13(similar in form to a cobra Type declaration) rather than a leading syntactic punctuated clause  
     14(C# square brackets or Java @named-annotation). 
     15 
     16Minimally, Attributes can be provided on classes and methods, class Fields and properties. 
     17 
     18== Grammar == 
     19 
     20{{{ 
     21... has <Attribute>[, <Attribute> ...] 
     22}}} 
     23 
     24may be optionally appended to the declaration of a Type (Class, Struct, Interface, Mixin, Enum, Extension, Event, Signature ) or 
     25to a Types Field ('''vars'''), Methods and Properties to provide an Attribute or Attributes on that item. 
     26 
     27They can also be given on a methods parameters or an Assembly declaration. 
     28 
     29== Examples == 
     30 
     31With respect to GTK 
     32 
    633{{{ 
    734#!cobra 
    8 class HasAnAttribute 
    9   has TreeNode(listOnly=true) 
     35class NameTreeNode 
     36  has TreeNode(listOnly=true)  # this is an attribute ( with args) 
    1037 
    1138  var name is String 
     
    1542    pass 
    1643}}} 
     44 
     45 
     46In the following, A and B.oldMethod are marked obsolete with the System.Obsolete Attribute. 
     47(This is a .Net common attribute - in cobra it would read better if named '!IsObsolete' or '!ObsoleteMarkerAttribute') 
     48  
     49{{{ 
     50#!cobra 
     51class A has Obsolete("use class B") 
     52 
     53    def Method 
     54        pass 
     55 
     56class B 
     57     
     58    def oldMethod has Obsolete("use NewMethod", true) 
     59        pass 
     60 
     61    def newMethod 
     62        pass 
     63 
     64}}} 
     65 
     66 
     67== Platform == 
     68 
     69In .Net custom attributes can be defined by defining a class subclassed from System.Attribute. 
     70Attributes are named in Cobra as per declaration and use in C#. 
     71 
     72 
     73For Java, (.Net) Attributes are known as Annotations. The cobra declaration uses the same prefix but 
     74uses (subclasses) from Java Annotation definitions. 
     75 
     76 
     77== See Also ==  
     78 
     79[http://msdn.microsoft.com/en-us/library/z0w1kczw.aspx C# Attributes] 
     80 
     81[http://msdn.microsoft.com/en-us/library/sw480ze8.aspx C# Custom Attributes] 
     82 
     83[http://msdn.microsoft.com/en-us/library/z371wyft.aspx C#/.Net Common Attributes]