Skip to content

Commit c131744

Browse files
Optimized ICommand.Execute
1 parent 09ef2a1 commit c131744

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

Src/AsyncAwaitBestPractices.MVVM.nuspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata minClientVersion="2.5">
44
<id>AsyncAwaitBestPractices.MVVM</id>
5-
<version>3.1.0-pre4</version>
5+
<version>3.1.0-pre5</version>
66
<title>Task Extensions for MVVM</title>
77
<authors>Brandon Minnick, John Thiriet</authors>
88
<owners>Brandon Minnick</owners>
@@ -14,14 +14,14 @@
1414
<summary>Includes AsyncCommand and IAsyncCommand which allows ICommand to safely be used asynchronously with Task.</summary>
1515
<tags>task,fire and forget, threading, extensions, system.threading.tasks,async,await</tags>
1616
<dependencies>
17-
<dependency id="AsyncAwaitBestPractices" version="3.1.0-pre4" />
17+
<dependency id="AsyncAwaitBestPractices" version="3.1.0-pre5" />
1818
</dependencies>
1919
<releaseNotes>
2020
New In This Release:
2121
- Added `SafeFireAndForgetExtensions.RemoveDefaultExceptionHandling`
2222
- Fixed InvalidHandleEventException bug when using the incorrect overload for `WeakEventManager&lt;T&gt;.HandleEvent`
2323
- Fixed NullReferenceException when called `ICommand.Execute`
24-
- Lowered .NET Standard Dependency to .NET Standard 1.0
24+
- Improved .NET Standard Dependency to .NET Standard 1.0
2525
</releaseNotes>
2626
<repository type="git" url="https://github.com/brminnick/AsyncAwaitBestPractices.git" branch="Release-v3.1.0" commit="2ec750b7f1182ee33c60a10705db3cd09c8bddff" />
2727
<copyright>Copyright (c) 2018 Brandon Minnick</copyright>

Src/AsyncAwaitBestPractices.MVVM/AsyncCommand.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,24 @@ public event EventHandler CanExecuteChanged
6464

6565
void ICommand.Execute(object parameter)
6666
{
67-
if (parameter is T validParameter)
68-
ExecuteAsync(validParameter).SafeFireAndForget(_continueOnCapturedContext, _onException);
67+
switch (parameter)
68+
{
69+
case T validParameter:
70+
ExecuteAsync(validParameter).SafeFireAndForget(_continueOnCapturedContext, _onException);
71+
break;
72+
6973
#pragma warning disable CS8601 //Possible null reference assignment
70-
else if (parameter is null && !typeof(T).GetTypeInfo().IsValueType)
71-
ExecuteAsync((T)parameter).SafeFireAndForget(_continueOnCapturedContext, _onException);
74+
case null when !typeof(T).GetTypeInfo().IsValueType:
75+
ExecuteAsync((T)parameter).SafeFireAndForget(_continueOnCapturedContext, _onException);
76+
break;
7277
#pragma warning restore CS8601
73-
else if (parameter is null)
74-
throw new InvalidCommandParameterException(typeof(T));
75-
else
76-
throw new InvalidCommandParameterException(typeof(T), parameter.GetType());
78+
79+
case null:
80+
throw new InvalidCommandParameterException(typeof(T));
81+
82+
default:
83+
throw new InvalidCommandParameterException(typeof(T), parameter.GetType());
84+
}
7785
}
7886
}
7987

Src/AsyncAwaitBestPractices.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata minClientVersion="2.5">
44
<id>AsyncAwaitBestPractices</id>
5-
<version>3.1.0-pre4</version>
5+
<version>3.1.0-pre5</version>
66
<title>Task Extensions for System.Threading.Tasks</title>
77
<authors>Brandon Minnick, John Thiriet</authors>
88
<owners>Brandon Minnick</owners>

0 commit comments

Comments
 (0)