Skip to content

Commit 113f3e8

Browse files
committed
C#: Add property test case where the field keyword is used.
1 parent edb2ed8 commit 113f3e8

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

csharp/ql/test/library-tests/properties/PrintAst.expected

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,19 @@ properties.cs:
230230
#-----| 2: (Parameters)
231231
# 124| 0: [Parameter] value
232232
# 124| 4: [BlockStmt] {...}
233+
# 128| 10: [Class] UseFieldKeyword
234+
# 130| 6: [Property] Prop
235+
# 130| -1: [TypeMention] object
236+
# 132| 3: [Getter] get_Prop
237+
# 132| 4: [BlockStmt] {...}
238+
# 132| 0: [ReturnStmt] return ...;
239+
# 132| 0: [FieldAccess] access to field Prop.field
240+
# 133| 4: [Setter] set_Prop
241+
#-----| 2: (Parameters)
242+
# 133| 0: [Parameter] value
243+
# 133| 4: [BlockStmt] {...}
244+
# 133| 0: [ExprStmt] ...;
245+
# 133| 0: [AssignExpr] ... = ...
246+
# 133| 0: [FieldAccess] access to field Prop.field
247+
# 133| 1: [ParameterAccess] access to parameter value
248+
# 130| 7: [Field] Prop.field

csharp/ql/test/library-tests/properties/Properties17.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| Prop.field |
12
| caption |
23
| next |
34
| y |

csharp/ql/test/library-tests/properties/Properties17.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @name Test that there are no backing fields
2+
* @name Test that there are no backing fields except for properties that use the `field` keyword in their getter or setter.
33
*/
44

55
import csharp

csharp/ql/test/library-tests/properties/properties.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,13 @@ int InterfaceWithProperties.Prop2
124124
set { }
125125
}
126126
}
127+
128+
class UseFieldKeyword
129+
{
130+
public object Prop
131+
{
132+
get { return field; }
133+
set { field = value; }
134+
}
135+
}
127136
}

0 commit comments

Comments
 (0)