File tree Expand file tree Collapse file tree
docs/programming-languages/attributes-annotations-decorators Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11``` C
2- // TODO
2+ // No Standard Attribute System before C23.
3+ // Compilers commonly provide extensions such as GCC attributes.
4+
5+ __attribute__ ((deprecated))
6+ void old_function()
7+ {
8+ // ...
9+ }
10+
11+ __ attribute__ ((unused))
12+ static int my_variable;
313```
414> More Info:
515> - http://unixwiz.net/techtips/gnu-c-attributes.html
Original file line number Diff line number Diff line change @@ -26,13 +26,50 @@ public class MyClass
2626```
2727
2828``` Cs
29- // TODO: Examples
29+ // ------------------------------------
30+ // Other Standard Attributes
31+ // ------------------------------------
32+
33+ [Serializable ]
34+ public class User
35+ {
36+ // ...
37+ }
38+
39+ [Flags ]
40+ public enum FileAccess
41+ {
42+ Read = 1 ,
43+ Write = 2 ,
44+ Execute = 4
45+ }
46+
47+ [Conditional (" DEBUG" )]
48+ public void LogDebug (string message )
49+ {
50+ // ...
51+ }
3052```
3153
3254``` Cs
3355// ------------------------------------
3456// Custom Attributes
3557// ------------------------------------
3658
37- // TODO: Examples
59+ [AttributeUsage (AttributeTargets .Class | AttributeTargets .Method )]
60+ public class DocumentationAttribute : Attribute
61+ {
62+ public string Message { get ; }
63+
64+ public DocumentationAttribute (string message )
65+ {
66+ Message = message ;
67+ }
68+ }
69+
70+ [Documentation (" Used by the syntax reference examples" )]
71+ public class MyClass
72+ {
73+ // ...
74+ }
3875```
Original file line number Diff line number Diff line change 11``` Go
2- // TODO
2+ // Go has no general attribute/annotation syntax.
3+ // Struct tags are metadata strings used by packages such as encoding/json.
4+
5+ type User struct {
6+ Name string ` json:"name"`
7+ Age int ` json:"age,omitempty"`
8+ }
9+
10+ // Compiler directives exist as comments for specific toolchain behavior.
11+ // go:noinline
12+ func myFunction () {
13+ // ...
14+ }
315```
Original file line number Diff line number Diff line change @@ -16,15 +16,46 @@ public void MyMethod()
1616```
1717
1818``` Java
19- // TODO: Examples
19+ // ------------------------------------
20+ // Other Standard Annotations
21+ // ------------------------------------
22+
23+ @Override
24+ public String toString()
25+ {
26+ return " MyClass" ;
27+ }
28+
29+ @SuppressWarnings (" unchecked" )
30+ public void myMethod()
31+ {
32+ // ...
33+ }
34+
35+ @FunctionalInterface
36+ public interface Operation
37+ {
38+ int apply (int first , int second );
39+ }
2040```
2141
2242``` Java
2343// ------------------------------------
2444// Custom Annotation
2545// ------------------------------------
2646
27- // TODO: Examples
47+ @Retention (RetentionPolicy . RUNTIME )
48+ @Target ({ ElementType . TYPE , ElementType . METHOD })
49+ public @interface Documentation
50+ {
51+ String value ();
52+ }
53+
54+ @Documentation (" Used by the syntax reference examples" )
55+ public class MyClass
56+ {
57+ // ...
58+ }
2859```
2960
3061> More Info:
Original file line number Diff line number Diff line change @@ -23,5 +23,17 @@ class SomeClass(object):
2323# Custom Decorator
2424# ------------------------------------
2525
26- # TODO : Examples
26+ from functools import wraps
27+
28+ def trace (function ):
29+ @wraps (function)
30+ def wrapper (* args , ** kwargs ):
31+ print (f " Calling { function.__name__ } " )
32+ return function(* args, ** kwargs)
33+
34+ return wrapper
35+
36+ @trace
37+ def add (first , second ):
38+ return first + second
2739```
Original file line number Diff line number Diff line change 11``` Rust
2- // TODO
2+ #[derive(Debug , Clone )]
3+ struct User {
4+ name : String ,
5+ }
6+
7+ #[deprecated(note = " Use new_function instead" )]
8+ fn old_function () {
9+ // ...
10+ }
11+
12+ #[allow(dead_code)]
13+ fn helper () {
14+ // ...
15+ }
316```
You can’t perform that action at this time.
0 commit comments