Skip to content

Commit 62e6d2f

Browse files
committed
Applied [MemberNotNull()] attribute to ContentType, Key setters
This allows us to remove the ugly hack of setting the local `_key` and `_contentType` variables to themselves at the end of the constructor to assure Roslyn code analysis that those were, in fact, set.
1 parent 8d1bcbd commit 62e6d2f

1 file changed

Lines changed: 2 additions & 9 deletions

File tree

OnTopic/Topic.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ public Topic(string key, string contentType, Topic? parent = null, int id = -1)
8787
Parent = parent;
8888
}
8989

90-
/*------------------------------------------------------------------------------------------------------------------------
91-
| Initialize key fields
92-
\-----------------------------------------------------------------------------------------------------------------------*/
93-
//###HACK JJC20190924: The local backing fields _key and _contentType are always initialized at this point. But Roslyn's
94-
//flow analysis isn't smart enough to detect this. As such, the following effectively sets _key and _contentType to
95-
//themselves.
96-
_key = Key;
97-
_contentType = ContentType;
98-
9990
}
10091

10192
#region Core Properties
@@ -183,6 +174,7 @@ public Topic? Parent {
183174
/// </value>
184175
public string ContentType {
185176
get => _contentType;
177+
[MemberNotNull(nameof(_contentType))]
186178
set {
187179
TopicFactory.ValidateKey(value);
188180
if (_contentType == value) {
@@ -215,6 +207,7 @@ public string ContentType {
215207
/// </requires>
216208
public string Key {
217209
get => _key;
210+
[MemberNotNull(nameof(_key))]
218211
set {
219212
TopicFactory.ValidateKey(value);
220213
if (_key == value) {

0 commit comments

Comments
 (0)