Skip to content

Commit

Permalink
Add parameter support to DelegateCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
tibel committed May 14, 2014
1 parent 5bbfc12 commit 716b5f1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions nuget/Caliburn.Light.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<metadata>
<id>Caliburn.Light</id>
<title>Caliburn.Light</title>
<version>1.1.0</version>
<version>1.2.0</version>
<authors>Thomas Ibel</authors>
<description>Fork of Caliburn.Micro that integrates some ideas of Prism and MVVMLight including a modular approach and weak events.</description>
<language>en-US</language>
<licenseUrl>https://github.com/tibel/Caliburn.Light/raw/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/tibel/Caliburn.Light</projectUrl>
<iconUrl>https://github.com/tibel/Caliburn.Light/raw/master/logo.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>Add support for special values.</releaseNotes>
<releaseNotes>Add parameter support to DelegateCommand.</releaseNotes>
<copyright>Copyright Thomas Ibel 2014</copyright>
<tags>Caliburn MVVM WPF WP8 WinRT Screen Coroutine EventAggregator Behavior Model-View-ViewModel Presentation UI ViewModel Phone IoC Validation Command</tags>

Expand Down
26 changes: 24 additions & 2 deletions src/Caliburn.Core/Action/DelegateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Caliburn.Light
/// <summary>
/// Wraps a ViewModel method (with guard) in an <see cref="ICommand"/>.
/// </summary>
/// <remarks>When using a property as guard then <see cref="CanExecuteChanged"/> is raised automatically.</remarks>
public sealed class DelegateCommand : ICommand
{
private readonly object _target;
Expand All @@ -31,6 +32,17 @@ public static DelegateCommand Create(Action action)
return CreateInternal(action);
}

/// <summary>
/// Creates a new <see cref="DelegateCommand"/> from the specified <paramref name="action"/>.
/// </summary>
/// <typeparam name="T">The type of the parameter.</typeparam>
/// <param name="action">The action.</param>
/// <returns>The new <see cref="DelegateCommand"/>.</returns>
public static DelegateCommand Create<T>(Action<T> action)
{
return CreateInternal(action);
}

/// <summary>
/// Creates a new <see cref="DelegateCommand"/> from the specified <paramref name="action"/>.
/// </summary>
Expand All @@ -42,14 +54,24 @@ public static DelegateCommand Create<TResult>(Func<TResult> action)
return CreateInternal(action);
}

/// <summary>
/// Creates a new <see cref="DelegateCommand"/> from the specified <paramref name="action"/>.
/// </summary>
/// <typeparam name="T">The type of the parameter.</typeparam>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <param name="action">The action.</param>
/// <returns>The new <see cref="DelegateCommand"/>.</returns>
public static DelegateCommand Create<T, TResult>(Func<T, TResult> action)
{
return CreateInternal(action);
}

private static DelegateCommand CreateInternal(Delegate action)
{
if (action == null)
throw new ArgumentNullException("action");
if (action.Target == null)
throw new ArgumentException("Method cannot be static.", "action");
if (action.GetMethodInfo().IsClosure())
throw new ArgumentException("A closure cannot be used.", "action");

return new DelegateCommand(action.Target, action.GetMethodInfo());
}
Expand Down
4 changes: 2 additions & 2 deletions src/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
[assembly: CLSCompliant(true)]
#endif

[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]

0 comments on commit 716b5f1

Please sign in to comment.