5 | | You can add attributes to classes and functions and variables also properties e.g. In GTK |
| 3 | Attributes are items of metadata appended to specific program items that end up supplied with your program.[[BR]] |
| 4 | |
| 5 | Some of these are given as of standard (Types and Members).[[BR]] |
| 6 | |
| 7 | User defined or Custom attributes can be declared and given to specify additional information required or desired.[[BR]] |
| 8 | |
| 9 | These attributes provided can be then queried by standard or additional tools or by runtime examination (reflection). |
| 10 | |
| 11 | Cobra provides for the declaration and use of attributes similarly to C# ( on .Net) and Java Language (on Jvm). |
| 12 | These 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 | |
| 16 | Minimally, Attributes can be provided on classes and methods, class Fields and properties. |
| 17 | |
| 18 | == Grammar == |
| 19 | |
| 20 | {{{ |
| 21 | ... has <Attribute>[, <Attribute> ...] |
| 22 | }}} |
| 23 | |
| 24 | may be optionally appended to the declaration of a Type (Class, Struct, Interface, Mixin, Enum, Extension, Event, Signature ) or |
| 25 | to a Types Field ('''vars'''), Methods and Properties to provide an Attribute or Attributes on that item. |
| 26 | |
| 27 | They can also be given on a methods parameters or an Assembly declaration. |
| 28 | |
| 29 | == Examples == |
| 30 | |
| 31 | With respect to GTK |
| 32 | |
| 44 | |
| 45 | |
| 46 | In 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 |
| 51 | class A has Obsolete("use class B") |
| 52 | |
| 53 | def Method |
| 54 | pass |
| 55 | |
| 56 | class 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 | |
| 69 | In .Net custom attributes can be defined by defining a class subclassed from System.Attribute. |
| 70 | Attributes are named in Cobra as per declaration and use in C#. |
| 71 | |
| 72 | |
| 73 | For Java, (.Net) Attributes are known as Annotations. The cobra declaration uses the same prefix but |
| 74 | uses (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] |