Skip to content

Commit 344e7d9

Browse files
committed
Taking advantage of C# 7.3 language features
1 parent 731edd6 commit 344e7d9

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

fNbt/Tags/NbtCompound.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,10 @@ internal void RenameTag([NotNull] string oldName, [NotNull] string newName) {
207207
Debug.Assert(oldName != null);
208208
Debug.Assert(newName != null);
209209
Debug.Assert(newName != oldName);
210-
NbtTag tag;
211-
if (tags.TryGetValue(newName, out tag)) {
210+
if (tags.TryGetValue(newName, out _)) {
212211
throw new ArgumentException("Cannot rename: a tag with the name already exists in this compound.");
213212
}
214-
if (!tags.TryGetValue(oldName, out tag)) {
213+
if (!tags.TryGetValue(oldName, out NbtTag tag)) {
215214
throw new ArgumentException("Cannot rename: no tag found to rename.");
216215
}
217216
tags.Remove(oldName);

fNbt/Tags/NbtTag.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public string Name {
4242
return;
4343
}
4444

45-
var parentAsCompound = Parent as NbtCompound;
46-
if (parentAsCompound != null) {
45+
if (Parent is NbtCompound parentAsCompound) {
4746
if (value == null) {
4847
throw new ArgumentNullException(nameof(value),
4948
"Name of tags inside an NbtCompound may not be null.");
@@ -67,8 +66,7 @@ public string Path {
6766
if (Parent == null) {
6867
return Name ?? "";
6968
}
70-
var parentAsList = Parent as NbtList;
71-
if (parentAsList != null) {
69+
if (Parent is NbtList parentAsList) {
7270
return parentAsList.Path + '[' + parentAsList.IndexOf(this) + ']';
7371
} else {
7472
return Parent.Path + '.' + Name;

0 commit comments

Comments
 (0)