Browse Source

Refactor exceptions and null checks

Equbuxu 3 years ago
parent
commit
ad8d8d2be7
25 changed files with 65 additions and 78 deletions
  1. 2 2
      src/ChangeableDocument/Changeables/Document.cs
  2. 1 1
      src/ChangeableDocument/Changes/CreateStructureMember_Change.cs
  3. 1 3
      src/ChangeableDocument/Changes/Drawing/ClearSelection_Change.cs
  4. 1 3
      src/ChangeableDocument/Changes/Drawing/CombineStructureMembersOnto_Change.cs
  5. 1 3
      src/ChangeableDocument/Changes/Drawing/DrawRectangle_UpdateableChange.cs
  6. 1 4
      src/ChangeableDocument/Changes/Drawing/SelectRectangle_UpdateableChange.cs
  7. 1 3
      src/ChangeableDocument/Changes/StructureMemberIsVisible_Change.cs
  8. 2 2
      src/ChangeableDocument/Changes/StructureMemberName_Change.cs
  9. 9 9
      src/ChangeableDocument/DocumentChangeTracker.cs
  10. 2 2
      src/ChangeableDocument/Rendering/ChunkRenderer.cs
  11. 2 2
      src/ChunkyImageLib/ChunkPool.cs
  12. 6 6
      src/ChunkyImageLib/ChunkyImage.cs
  13. 4 4
      src/ChunkyImageLib/CommittedChunkStorage.cs
  14. 1 1
      src/ChunkyImageLib/DataHolders/Vector2d.cs
  15. 1 1
      src/ChunkyImageLib/DataHolders/Vector2i.cs
  16. 1 1
      src/ChunkyImageLib/Operations/RectangleOperation.cs
  17. 2 2
      src/ChunkyImageLib/Surface.cs
  18. 5 5
      src/PixiEditorPrototype/Behaviors/SliderUpdateBehavior.cs
  19. 6 6
      src/PixiEditorPrototype/Models/DocumentStructureHelper.cs
  20. 2 2
      src/PixiEditorPrototype/Models/DocumentUpdater.cs
  21. 6 6
      src/PixiEditorPrototype/Models/Rendering/WriteableBitmapUpdater.cs
  22. 1 3
      src/PixiEditorPrototype/ReverseOrderStackPanel.cs
  23. 4 4
      src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs
  24. 2 2
      src/PixiEditorPrototype/ViewModels/StructureMemberViewModel.cs
  25. 1 1
      src/PixiEditorPrototype/Views/DocumentView.xaml.cs

+ 2 - 2
src/ChangeableDocument/Changeables/Document.cs

@@ -17,7 +17,7 @@ namespace ChangeableDocument.Changeables
         internal Selection Selection { get; } = new();
         public Vector2i Size { get; set; } = DefaultSize;
 
-        public StructureMember FindMemberOrThrow(Guid guid) => FindMember(guid) ?? throw new Exception("Could not find member with guid " + guid.ToString());
+        public StructureMember FindMemberOrThrow(Guid guid) => FindMember(guid) ?? throw new ArgumentException("Could not find member with guid " + guid.ToString());
         public StructureMember? FindMember(Guid guid)
         {
             var list = FindMemberPath(guid);
@@ -28,7 +28,7 @@ namespace ChangeableDocument.Changeables
         {
             var path = FindMemberPath(childGuid);
             if (path.Count < 2)
-                throw new Exception("Couldn't find child and parent");
+                throw new ArgumentException("Couldn't find child and parent");
             return (path[0], (Folder)path[1]);
         }
 

+ 1 - 1
src/ChangeableDocument/Changes/CreateStructureMember_Change.cs

@@ -29,7 +29,7 @@ namespace ChangeableDocument.Changes
             {
                 StructureMemberType.Layer => new Layer(document.Size) { GuidValue = newMemberGuid },
                 StructureMemberType.Folder => new Folder() { GuidValue = newMemberGuid },
-                _ => throw new Exception("Cannon create member of type " + type.ToString())
+                _ => throw new InvalidOperationException("Cannon create member of type " + type.ToString())
             };
 
             folder.Children.Insert(parentFolderIndex, member);

+ 1 - 3
src/ChangeableDocument/Changes/Drawing/ClearSelection_Change.cs

@@ -38,12 +38,10 @@ namespace ChangeableDocument.Changes.Drawing
         {
             if (originalIsEmpty)
                 return new Selection_ChangeInfo() { Chunks = new() };
-            if (savedSelection == null)
-                throw new Exception("No saved selection to restore");
             target.Selection.IsEmptyAndInactive = false;
 
             target.Selection.SelectionImage.CancelChanges();
-            savedSelection.ApplyChunksToImage(target.Selection.SelectionImage);
+            savedSelection!.ApplyChunksToImage(target.Selection.SelectionImage);
             HashSet<Vector2i> affChunks = target.Selection.SelectionImage.FindAffectedChunks();
             target.Selection.SelectionImage.CommitChanges();
 

+ 1 - 3
src/ChangeableDocument/Changes/Drawing/CombineStructureMembersOnto_Change.cs

@@ -76,10 +76,8 @@ namespace ChangeableDocument.Changes.Drawing
         public override IChangeInfo? Revert(Document target)
         {
             Layer toDrawOn = (Layer)target.FindMemberOrThrow(targetLayer);
-            if (originalChunks == null)
-                throw new Exception("No saved chunks to restore");
 
-            originalChunks.ApplyChunksToImage(toDrawOn.LayerImage);
+            originalChunks!.ApplyChunksToImage(toDrawOn.LayerImage);
             var affectedChunks = toDrawOn.LayerImage.FindAffectedChunks();
             toDrawOn.LayerImage.CommitChanges();
 

+ 1 - 3
src/ChangeableDocument/Changes/Drawing/DrawRectangle_UpdateableChange.cs

@@ -53,10 +53,8 @@ namespace ChangeableDocument.Changes.Drawing
 
         public override IChangeInfo? Revert(Document target)
         {
-            if (storedChunks == null)
-                throw new Exception("No stored chunks to revert to");
             Layer layer = (Layer)target.FindMemberOrThrow(layerGuid);
-            storedChunks.ApplyChunksToImage(layer.LayerImage);
+            storedChunks!.ApplyChunksToImage(layer.LayerImage);
             storedChunks.Dispose();
             storedChunks = null;
             var changes = new LayerImageChunks_ChangeInfo()

+ 1 - 4
src/ChangeableDocument/Changes/Drawing/SelectRectangle_UpdateableChange.cs

@@ -50,11 +50,8 @@ namespace ChangeableDocument.Changes.Drawing
 
         public override IChangeInfo? Revert(Document target)
         {
-            if (originalSelectionState == null)
-                throw new Exception("No stored chunks to revert to");
-
             target.Selection.IsEmptyAndInactive = originalIsEmpty;
-            originalSelectionState.ApplyChunksToImage(target.Selection.SelectionImage);
+            originalSelectionState!.ApplyChunksToImage(target.Selection.SelectionImage);
             originalSelectionState.Dispose();
             originalSelectionState = null;
             var changes = new Selection_ChangeInfo() { Chunks = target.Selection.SelectionImage.FindAffectedChunks() };

+ 1 - 3
src/ChangeableDocument/Changes/StructureMemberIsVisible_Change.cs

@@ -33,9 +33,7 @@ namespace ChangeableDocument.Changes
 
         public override IChangeInfo? Revert(Document target)
         {
-            if (originalIsVisible == null)
-                throw new Exception("No name to revert to");
-            target.FindMemberOrThrow(targetMember).IsVisible = originalIsVisible.Value;
+            target.FindMemberOrThrow(targetMember).IsVisible = originalIsVisible!.Value;
             return new StructureMemberIsVisible_ChangeInfo() { GuidValue = targetMember };
         }
     }

+ 2 - 2
src/ChangeableDocument/Changes/StructureMemberName_Change.cs

@@ -35,8 +35,8 @@ namespace ChangeableDocument.Changes
 
         public override IChangeInfo? Revert(Document target)
         {
-            if (originalName == null)
-                throw new Exception("No name to revert to");
+            if (originalName is null)
+                throw new InvalidOperationException("No name to revert to");
             target.FindMemberOrThrow(targetMember).Name = originalName;
             return new StructureMemberName_ChangeInfo() { GuidValue = targetMember };
         }

+ 9 - 9
src/ChangeableDocument/DocumentChangeTracker.cs

@@ -73,7 +73,7 @@ namespace ChangeableDocument
         private List<Change> PopLatestChanges(int count)
         {
             if (redoStack.Count > 0)
-                throw new Exception("There are changes in the redo stack");
+                throw new InvalidOperationException("There are changes in the redo stack");
             List<Change> popped = new();
             while (count > 0)
             {
@@ -94,7 +94,7 @@ namespace ChangeableDocument
         private void MergeLatestChanges(int count)
         {
             if (redoStack.Count > 0)
-                throw new Exception("There are changes in the redo stack");
+                throw new InvalidOperationException("There are changes in the redo stack");
             var packet = PopLatestChanges(count);
             if (packet.Count > 0)
                 undoStack.Push(packet);
@@ -114,8 +114,8 @@ namespace ChangeableDocument
 
         private IChangeInfo? ProcessMakeChangeAction(IMakeChangeAction act)
         {
-            if (activeChange != null)
-                throw new Exception("Can't make a change while another change is active");
+            if (activeChange is not null)
+                throw new InvalidOperationException("Can't make a change while another change is active");
             var change = act.CreateCorrespondingChange();
             change.Initialize(document);
             var info = change.Apply(document, out bool ignoreInUndo);
@@ -128,7 +128,7 @@ namespace ChangeableDocument
 
         private IChangeInfo? ProcessStartOrUpdateChangeAction(IStartOrUpdateChangeAction act)
         {
-            if (activeChange == null)
+            if (activeChange is null)
             {
                 activeChange = act.CreateCorrespondingChange();
                 activeChange.Initialize(document);
@@ -139,10 +139,10 @@ namespace ChangeableDocument
 
         private IChangeInfo? ProcessEndChangeAction(IEndChangeAction act)
         {
-            if (activeChange == null)
-                throw new Exception("Can't end a change: no changes are active");
+            if (activeChange is null)
+                throw new InvalidOperationException("Can't end a change: no changes are active");
             if (!act.IsChangeTypeMatching(activeChange))
-                throw new Exception($"Trying to end a change via action of type {act.GetType()} while a change of type {activeChange.GetType()} is active");
+                throw new InvalidOperationException($"Trying to end a change via action of type {act.GetType()} while a change of type {activeChange.GetType()} is active");
 
             var info = activeChange.Apply(document, out bool ignoreInUndo);
             if (!ignoreInUndo)
@@ -182,7 +182,7 @@ namespace ChangeableDocument
                         DeleteAllChanges();
                         break;
                     default:
-                        throw new Exception("Unknown action type");
+                        throw new InvalidOperationException("Unknown action type");
                 }
             }
             return changeInfos;

+ 2 - 2
src/ChangeableDocument/Rendering/ChunkRenderer.cs

@@ -26,10 +26,10 @@ namespace ChangeableDocument.Rendering
             {
                 if (!child.IsVisible)
                     continue;
-                if (child is IReadOnlyLayer layer && (visibleLayers == null || visibleLayers.Contains(layer.GuidValue)))
+                if (child is IReadOnlyLayer layer && (visibleLayers is null || visibleLayers.Contains(layer.GuidValue)))
                 {
                     IReadOnlyChunk? chunk = layer.ReadOnlyLayerImage.GetLatestChunk(chunkPos);
-                    if (chunk == null)
+                    if (chunk is null)
                         continue;
                     PaintToDrawChunksWith.Color = new SKColor(255, 255, 255, (byte)Math.Round(child.Opacity * 255));
                     chunk.DrawOnSurface(targetChunk.Surface.SkiaSurface, new(0, 0), PaintToDrawChunksWith);

+ 2 - 2
src/ChunkyImageLib/ChunkPool.cs

@@ -14,11 +14,11 @@ namespace ChunkyImageLib
         {
             get
             {
-                if (instance == null)
+                if (instance is null)
                 {
                     lock (lockObj)
                     {
-                        if (instance == null)
+                        if (instance is null)
                             instance = new ChunkPool();
                     }
                 }

+ 6 - 6
src/ChunkyImageLib/ChunkyImage.cs

@@ -42,7 +42,7 @@ namespace ChunkyImageLib
             foreach (var chunk in chunks)
             {
                 var image = (Chunk?)GetLatestChunk(chunk);
-                if (image != null)
+                if (image is not null)
                     output.DrawImage(chunk * ChunkSize, image.Surface);
             }
             output.CommitChanges();
@@ -183,7 +183,7 @@ namespace ChunkyImageLib
             {
                 LatestChunkData data = latestChunksData[pos];
                 if (data.QueueProgress != queuedOperations.Count)
-                    throw new Exception("Trying to commit chunk that wasn't fully processed");
+                    throw new InvalidOperationException("Trying to commit a chunk that wasn't fully processed");
 
                 if (committedChunks.ContainsKey(pos))
                 {
@@ -219,7 +219,7 @@ namespace ChunkyImageLib
                 if (operation is RasterClipOperation clipOperation)
                 {
                     var chunk = clipOperation.ClippingMask.GetCommittedChunk(chunkPos);
-                    if (chunk != null)
+                    if (chunk is not null)
                         activeClips.Add(chunk);
                     else
                         isFullyMaskedOut = true;
@@ -306,7 +306,7 @@ namespace ChunkyImageLib
         private void FindAndDeleteEmptyCommittedChunks()
         {
             if (queuedOperations.Count != 0)
-                throw new Exception("This method cannot be used while any operations are queued");
+                throw new InvalidOperationException("This method cannot be used while any operations are queued");
             HashSet<Vector2i> toRemove = new();
             foreach (var (pos, chunk) in committedChunks)
             {
@@ -337,12 +337,12 @@ namespace ChunkyImageLib
         {
             Chunk? targetChunk;
             targetChunk = MaybeGetChunk(chunkPos, latestChunks);
-            if (targetChunk == null)
+            if (targetChunk is null)
             {
                 targetChunk = Chunk.Create();
                 var maybeCommittedChunk = MaybeGetChunk(chunkPos, committedChunks);
 
-                if (maybeCommittedChunk != null)
+                if (maybeCommittedChunk is not null)
                     maybeCommittedChunk.Surface.CopyTo(targetChunk.Surface);
                 else
                     targetChunk.Surface.SkiaSurface.Canvas.Clear();

+ 4 - 4
src/ChunkyImageLib/CommittedChunkStorage.cs

@@ -11,7 +11,7 @@ namespace ChunkyImageLib
             foreach (var chunkPos in committedChunksToSave)
             {
                 Chunk? chunk = (Chunk?)image.GetCommittedChunk(chunkPos);
-                if (chunk == null)
+                if (chunk is null)
                 {
                     savedChunks.Add((chunkPos, null));
                     continue;
@@ -25,10 +25,10 @@ namespace ChunkyImageLib
         public void ApplyChunksToImage(ChunkyImage image)
         {
             if (disposed)
-                throw new Exception("This instance has been disposed");
+                throw new ObjectDisposedException(nameof(CommittedChunkStorage));
             foreach (var (pos, chunk) in savedChunks)
             {
-                if (chunk == null)
+                if (chunk is null)
                     image.ClearRegion(pos * ChunkPool.FullChunkSize, new(ChunkPool.FullChunkSize, ChunkPool.FullChunkSize));
                 else
                     image.DrawImage(pos * ChunkPool.FullChunkSize, chunk.Surface);
@@ -41,7 +41,7 @@ namespace ChunkyImageLib
                 return;
             foreach (var (_, chunk) in savedChunks)
             {
-                if (chunk != null)
+                if (chunk is not null)
                     chunk.Dispose();
             }
         }

+ 1 - 1
src/ChunkyImageLib/DataHolders/Vector2d.cs

@@ -138,7 +138,7 @@ namespace ChunkyImageLib.DataHolders
         public override bool Equals(object? obj)
         {
             var item = obj as Vector2d?;
-            if (item == null)
+            if (item is null)
                 return false;
             return this == item;
         }

+ 1 - 1
src/ChunkyImageLib/DataHolders/Vector2i.cs

@@ -87,7 +87,7 @@ namespace ChunkyImageLib.DataHolders
         public override bool Equals(object? obj)
         {
             var item = obj as Vector2i?;
-            if (item == null)
+            if (item is null)
                 return false;
             return this == item;
         }

+ 1 - 1
src/ChunkyImageLib/Operations/RectangleOperation.cs

@@ -68,7 +68,7 @@ namespace ChunkyImageLib.Operations
             //find inner stroke boudaries in pixel coords
             var xInset = Inset(Data.Pos.X, Data.MaxPos.X, Data.StrokeWidth);
             var yInset = Inset(Data.Pos.Y, Data.MaxPos.Y, Data.StrokeWidth);
-            if (xInset == null || yInset == null)
+            if (xInset is null || yInset is null)
                 return GetChunksForFilled(chunkSize);
 
             //find two chunk rectanges, outer and inner

+ 2 - 2
src/ChunkyImageLib/Surface.cs

@@ -62,8 +62,8 @@ namespace ChunkyImageLib
         private SKSurface CreateSKSurface()
         {
             var surface = SKSurface.Create(new SKImageInfo(Size.X, Size.Y, SKColorType.RgbaF16, SKAlphaType.Premul, SKColorSpace.CreateSrgbLinear()), PixelBuffer);
-            if (surface == null)
-                throw new Exception("Could not create surface");
+            if (surface is null)
+                throw new InvalidOperationException($"Could not create surface (Size:{Size})");
             return surface;
         }
 

+ 5 - 5
src/PixiEditorPrototype/Behaviors/SliderUpdateBehavior.cs

@@ -53,7 +53,7 @@ namespace PixiEditorPrototype.Behaviors
                 return;
             attached = true;
             var thumb = GetThumb(AssociatedObject);
-            if (thumb == null)
+            if (thumb is null)
                 return;
 
             thumb.DragStarted += Thumb_DragStarted;
@@ -66,7 +66,7 @@ namespace PixiEditorPrototype.Behaviors
             if (!attached)
                 return;
             var thumb = GetThumb(AssociatedObject);
-            if (thumb == null)
+            if (thumb is null)
                 return;
 
             thumb.DragStarted -= Thumb_DragStarted;
@@ -78,7 +78,7 @@ namespace PixiEditorPrototype.Behaviors
             var obj = (SliderUpdateBehavior)slider;
             if (obj.dragging)
             {
-                if (obj.DragValueChanged != null && obj.DragValueChanged.CanExecute(e.NewValue))
+                if (obj.DragValueChanged is not null && obj.DragValueChanged.CanExecute(e.NewValue))
                     obj.DragValueChanged.Execute(e.NewValue);
                 obj.valueChangedWhileDragging = true;
             }
@@ -87,7 +87,7 @@ namespace PixiEditorPrototype.Behaviors
         private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e)
         {
             dragging = false;
-            if (valueChangedWhileDragging == true && DragEnded != null && DragEnded.CanExecute(null))
+            if (valueChangedWhileDragging == true && DragEnded is not null && DragEnded.CanExecute(null))
                 DragEnded.Execute(null);
             valueChangedWhileDragging = false;
         }
@@ -100,7 +100,7 @@ namespace PixiEditorPrototype.Behaviors
         private static Thumb? GetThumb(Slider slider)
         {
             var track = slider.Template.FindName("PART_Track", slider) as Track;
-            return track == null ? null : track.Thumb;
+            return track is null ? null : track.Thumb;
         }
 
 

+ 6 - 6
src/PixiEditorPrototype/Models/DocumentStructureHelper.cs

@@ -16,7 +16,7 @@ namespace PixiEditorPrototype.Models
 
         public void CreateNewStructureMember(StructureMemberType type)
         {
-            if (doc.SelectedStructureMember == null)
+            if (doc.SelectedStructureMember is null)
             {
                 //put member on top
                 doc.ActionAccumulator.AddAction(new CreateStructureMember_Action(doc.StructureRoot.GuidValue, Guid.NewGuid(), doc.StructureRoot.Children.Count, type));
@@ -33,15 +33,15 @@ namespace PixiEditorPrototype.Models
                 //put member above the layer
                 var path = FindPath(layer.GuidValue);
                 if (path.Count < 2)
-                    throw new Exception("Couldn't find a path to the selected member");
+                    throw new InvalidOperationException("Couldn't find a path to the selected member");
                 var parent = (FolderViewModel)path[1];
                 doc.ActionAccumulator.AddAction(new CreateStructureMember_Action(parent.GuidValue, Guid.NewGuid(), parent.Children.IndexOf(layer) + 1, type));
                 return;
             }
-            throw new Exception("Unknown member type: " + type.ToString());
+            throw new ArgumentException("Unknown member type: " + type.ToString());
         }
 
-        public StructureMemberViewModel FindOrThrow(Guid guid) => Find(guid) ?? throw new Exception("Could not find member with guid " + guid.ToString());
+        public StructureMemberViewModel FindOrThrow(Guid guid) => Find(guid) ?? throw new ArgumentException("Could not find member with guid " + guid.ToString());
         public StructureMemberViewModel? Find(Guid guid)
         {
             var list = FindPath(guid);
@@ -52,7 +52,7 @@ namespace PixiEditorPrototype.Models
         {
             var path = FindPath(childGuid);
             if (path.Count < 2)
-                throw new Exception("Couldn't find child and parent");
+                throw new ArgumentException("Couldn't find child and parent");
             return (path[0], (FolderViewModel)path[1]);
         }
         public List<StructureMemberViewModel> FindPath(Guid guid)
@@ -92,7 +92,7 @@ namespace PixiEditorPrototype.Models
         {
             var path = FindPath(guid);
             if (path.Count < 2)
-                throw new Exception("Couldn't find the member to be moved");
+                throw new ArgumentException("Couldn't find the member to be moved");
             if (path.Count == 2)
             {
                 int curIndex = doc.StructureRoot.Children.IndexOf(path[0]);

+ 2 - 2
src/PixiEditorPrototype/Models/DocumentUpdater.cs

@@ -18,7 +18,7 @@ namespace PixiEditorPrototype.Models
 
         public void ApplyChangeFromChangeInfo(IChangeInfo? arbitraryInfo)
         {
-            if (arbitraryInfo == null)
+            if (arbitraryInfo is null)
                 return;
 
             switch (arbitraryInfo)
@@ -69,7 +69,7 @@ namespace PixiEditorPrototype.Models
             {
                 IReadOnlyLayer layer => new LayerViewModel(doc, layer),
                 IReadOnlyFolder folder => new FolderViewModel(doc, folder),
-                _ => throw new Exception("Unsupposed member type")
+                _ => throw new InvalidOperationException("Unsupposed member type")
             };
 
             parentFolderVM.Children.Insert(index, memberVM);

+ 6 - 6
src/PixiEditorPrototype/Models/Rendering/WriteableBitmapUpdater.cs

@@ -44,8 +44,8 @@ namespace PixiEditorPrototype.Models.Rendering
                 switch (change)
                 {
                     case LayerImageChunks_ChangeInfo layerImageChunks:
-                        if (layerImageChunks.Chunks == null)
-                            throw new Exception("Chunks must not be null");
+                        if (layerImageChunks.Chunks is null)
+                            throw new InvalidOperationException("Chunks must not be null");
                         chunks.UnionWith(layerImageChunks.Chunks);
                         break;
                     case Selection_ChangeInfo selection:
@@ -55,8 +55,8 @@ namespace PixiEditorPrototype.Models.Rendering
                         }
                         else
                         {
-                            if (selection.Chunks == null)
-                                throw new Exception("Chunks must not be null");
+                            if (selection.Chunks is null)
+                                throw new InvalidOperationException("Chunks must not be null");
                             chunks.UnionWith(selection.Chunks);
                         }
                         break;
@@ -95,7 +95,7 @@ namespace PixiEditorPrototype.Models.Rendering
             HashSet<Vector2i>? chunks = null;
             if (!redrawEverything)
                 chunks = FindChunksToRerender(changes);
-            if (chunks == null)
+            if (chunks is null)
                 redrawEverything = true;
 
 
@@ -144,7 +144,7 @@ namespace PixiEditorPrototype.Models.Rendering
             if (tracker.Document.ReadOnlySelection.ReadOnlyIsEmptyAndInactive)
                 return;
             IReadOnlyChunk? selectionChunk = tracker.Document.ReadOnlySelection.ReadOnlySelectionImage.GetLatestChunk(chunkPos);
-            if (selectionChunk != null)
+            if (selectionChunk is not null)
                 selectionChunk.DrawOnSurface(screenSurface, chunkPos * ChunkyImage.ChunkSize, SelectionPaint);
         }
     }

+ 1 - 3
src/PixiEditorPrototype/ReverseOrderStackPanel.cs

@@ -16,10 +16,8 @@ namespace PixiEditorPrototype
             System.Collections.Generic.IEnumerable<UIElement> children = InternalChildren.Cast<UIElement>().Reverse();
             foreach (UIElement child in children)
             {
-                if (child == null)
-                {
+                if (child is null)
                     continue;
-                }
 
                 if (fHorizontal)
                 {

+ 4 - 4
src/PixiEditorPrototype/ViewModels/DocumentViewModel.cs

@@ -142,7 +142,7 @@ namespace PixiEditorPrototype.ViewModels
         {
             if (activeTool == Tool.Rectangle)
             {
-                if (SelectedStructureMember == null)
+                if (SelectedStructureMember is null)
                     return;
                 startedDrawingRect = true;
                 ActionAccumulator.AddAction(new DrawRectangle_Action(
@@ -197,7 +197,7 @@ namespace PixiEditorPrototype.ViewModels
 
         public void DeleteStructureMember(object? param)
         {
-            if (SelectedStructureMember != null)
+            if (SelectedStructureMember is not null)
                 ActionAccumulator.AddAction(new DeleteStructureMember_Action(SelectedStructureMember.GuidValue));
         }
 
@@ -223,7 +223,7 @@ namespace PixiEditorPrototype.ViewModels
 
         private void Combine(object? param)
         {
-            if (SelectedStructureMember == null)
+            if (SelectedStructureMember is null)
                 return;
             List<Guid> selected = new();
             AddSelectedMembers(StructureRoot, selected);
@@ -261,7 +261,7 @@ namespace PixiEditorPrototype.ViewModels
 
         private void ChangeActiveTool(object? param)
         {
-            if (param == null)
+            if (param is null)
                 return;
             activeTool = (Tool)param;
         }

+ 2 - 2
src/PixiEditorPrototype/ViewModels/StructureMemberViewModel.cs

@@ -64,8 +64,8 @@ namespace PixiEditorPrototype.ViewModels
 
         private void UpdateOpacity(object? opacity)
         {
-            if (opacity == null || opacity is not double value)
-                throw new Exception("Can't update opacity");
+            if (opacity is not double value)
+                throw new ArgumentException("The passed value isn't a double");
             Document.ActionAccumulator.AddAction(new OpacityChange_Action(GuidValue, (float)value));
         }
     }

+ 1 - 1
src/PixiEditorPrototype/Views/DocumentView.xaml.cs

@@ -13,7 +13,7 @@ namespace PixiEditorPrototype.Views
             InitializeComponent();
             DataContextChanged += (_, e) =>
             {
-                if (e.NewValue != null)
+                if (e.NewValue is not null)
                     ((DocumentViewModel)e.NewValue).View = this;
             };
         }