Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jp2masa committed Aug 25, 2019
1 parent 5bfd1a7 commit 94ba340
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/Movere/Common/MaybeNullWhenFalseAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
internal sealed class MaybeNullWhenFalseAttribute : Attribute
{
}
}
8 changes: 4 additions & 4 deletions src/Movere/Common/StackExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#if NETSTANDARD2_0

using System.Runtime.CompilerServices;

namespace System.Collections.Generic
{
internal static class StackExtensions
{
public static bool TryPop<T>(this Stack<T> stack, out T result)
public static bool TryPop<T>(this Stack<T> stack, [MaybeNullWhenFalse] out T result)
{
if (stack.Count > 0)
{
result = stack.Pop();
return true;
}

#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter.
result = default;
#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter.
result = default!;
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Movere/ViewModels/FileExplorerTreeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public FileExplorerTreeViewModel()

FolderHierarchy = _drives.Select(d => new Folder(d.RootDirectory));

#pragma warning disable CS8619 // Nullability of reference types in value doesn't match target type.
SelectedFolderChanged = this.WhenAnyValue(vm => vm.SelectedFolder).Where(folder => folder != null);
#pragma warning restore CS8619 // Nullability of reference types in value doesn't match target type.
SelectedFolderChanged = from folder in this.WhenAnyValue(vm => vm.SelectedFolder)
where folder != null
select folder;
}

public IEnumerable<Folder> FolderHierarchy { get; }
Expand Down

0 comments on commit 94ba340

Please sign in to comment.