Skip to content

Commit 42ab14e

Browse files
Update UnsafeAccessorAttribute.xml (#9569)
Add example for private property.
1 parent c1a6a42 commit 42ab14e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

xml/System.Runtime.CompilerServices/UnsafeAccessorAttribute.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ By default, the attributed method's name dictates the name of the method/field.
6565
Class(int i) { PrivateField = i; }
6666
void PrivateMethod() { }
6767
int PrivateField;
68+
int PrivateProperty { get => PrivateField; }
6869
}
6970

7071
public void CallStaticPrivateMethod()
@@ -78,7 +79,6 @@ By default, the attributed method's name dictates the name of the method/field.
7879
{
7980
ref int f = ref GetSetStaticPrivateField(null);
8081

81-
8282
[UnsafeAccessor(UnsafeAccessorKind.StaticField, Name = "StaticPrivateField")]
8383
extern static ref int GetSetStaticPrivateField(Class c);
8484
}
@@ -90,7 +90,6 @@ By default, the attributed method's name dictates the name of the method/field.
9090

9191
PrivateCtorAsMethod(c2, 2);
9292

93-
9493
[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
9594
extern static Class PrivateCtor(int i);
9695

@@ -105,11 +104,17 @@ By default, the attributed method's name dictates the name of the method/field.
105104
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = nameof(PrivateMethod))]
106105
extern static void PrivateMethod(Class c);
107106
}
107+
public void GetPrivateProperty(Class c)
108+
{
109+
int f = GetPrivateProperty(c);
110+
111+
[UnsafeAccessor(UnsafeAccessorKind.Method, Name = "get_PrivateProperty")]
112+
extern static int GetPrivateProperty(Class c);
113+
}
108114
public void GetSetPrivateField(Class c)
109115
{
110116
ref int f = ref GetSetPrivateField(c);
111117

112-
113118
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "PrivateField")]
114119
extern static ref int GetSetPrivateField(Class c);
115120
}

0 commit comments

Comments
 (0)