@@ -6,10 +6,57 @@ namespace Robust.Shared.Analyzers.Implementation;
66namespace Robust . Shared . Analyzers ;
77#endif
88
9+ /// <summary>
10+ /// <para>
11+ /// Access is a way to describe how other classes are allowed to use a field in more precise terms than "can use"
12+ /// and "cannot use". Think of it like friend classes from C++.
13+ /// </para>
14+ /// <para>
15+ /// Access controls field, method, and property usage for three different kinds of users:
16+ /// Self (the declaring class), Friend (classes explicitly named as friends by the access attribute),
17+ /// and Other (classes that aren't the other two). Using <see cref="AccessPermissions"/> you can define what
18+ /// operations each of the users is allowed.
19+ /// </para>
20+ /// </summary>
21+ /// <example>
22+ /// <code>
23+ /// [RegisterComponent]
24+ /// // Allow the system with utility functions for this component to modify it.
25+ /// [Access(typeof(MySystem))]
26+ /// public sealed class MyComponent : Component
27+ /// {
28+ /// public int Counter;
29+ /// }
30+ /// <br/>
31+ /// public sealed class MySystem : EntitySystem
32+ /// {
33+ /// public void AddToCounter(Entity<MyComponent> entity)
34+ /// {
35+ /// // Works, we're a friend of the other type.
36+ /// entity.Comp.Counter += 1;
37+ /// }
38+ /// }
39+ /// <br/>
40+ /// public sealed class OtherSystem : EntitySystem
41+ /// {
42+ /// public void AddToCounter(Entity<MyComponent> entity)
43+ /// {
44+ /// // Error RS2008: Tried to perform write access to member 'Counter' in type 'MyComponent', despite read access.
45+ /// entity.Comp.Counter += 1;
46+ /// }
47+ /// }
48+ /// </code>
49+ /// </example>
50+ /// <seealso cref="AccessPermissions"/>
951[ AttributeUsage ( AttributeTargets . Class | AttributeTargets . Interface | AttributeTargets . Struct
1052 | AttributeTargets . Field | AttributeTargets . Property | AttributeTargets . Method | AttributeTargets . Constructor ) ]
1153public sealed class AccessAttribute : Attribute
1254{
55+ /// <summary>
56+ /// The list of types considered "friends" of the type with this attribute.
57+ /// These types get elevated permissions.
58+ /// </summary>
59+ /// <seealso cref="Friend"/>
1360 public readonly Type [ ] Friends ;
1461
1562 public const AccessPermissions SelfDefaultPermissions = AccessPermissions . ReadWriteExecute ;
@@ -20,7 +67,13 @@ public sealed class AccessAttribute : Attribute
2067 /// Access permissions for the type itself, or the type containing the member.
2168 /// </summary>
2269 public AccessPermissions Self { get ; set ; } = SelfDefaultPermissions ;
70+ /// <summary>
71+ /// Access permissions for types specified as <see cref="Friends"/>.
72+ /// </summary>
2373 public AccessPermissions Friend { get ; set ; } = FriendDefaultPermissions ;
74+ /// <summary>
75+ /// Access permissions for types that aren't <see cref="Self"/> and aren't <see cref="Friend"/>.
76+ /// </summary>
2477 public AccessPermissions Other { get ; set ; } = OtherDefaultPermissions ;
2578
2679 public AccessAttribute ( params Type [ ] friends )
0 commit comments