- FrictSLUnitTest.zip
- README.txt
- Sample.Silverlight.WCF.sln
- Source
- Sample.Silverlight.WCF.Tests.Clumsy.Web
- Sample.Silverlight.WCF.Tests.Clumsy
- Sample.Silverlight.WCF.Tests
- Sample.Silverlight.WCF.Web
- Sample.Silverlight.WCF
- Tools
- NUnit
- nunit.framework.dll
- nunit.silverlight.dll
- Rhino.Mocks
- Castle.Core-Silverlight.dll
- Castle.DynamicProxy-Silverlight.dll
- Rhino.Mocks 3.5.Silverlight.dll
|
#region Author
//// Rob Eisenberg, Blue Spire Consulting, Inc
#endregion
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Input;
using Sample.Silverlight.WCF.Infrastructure.Actions;
namespace Sample.Silverlight.WCF.Infrastructure
{
public class ViewModelCommand : ICommand
{
readonly MethodInfo execute;
readonly PropertyInfo canExecute;
readonly ViewModelBase viewModel;
public event EventHandler CanExecuteChanged = delegate { };
public ViewModelCommand(ViewModelBase viewModel, MethodInfo execute, PropertyInfo canExecute)
{
this.viewModel = viewModel;
this.execute = execute;
this.canExecute = canExecute;
ObserveCanExecuteChanged();
}
void ObserveCanExecuteChanged()
{
if (canExecute == null)
return;
viewModel.PropertyChanged += (s, e) =>
{
if (e.PropertyName == canExecute.Name)
CanExecuteChanged(this, EventArgs.Empty);
};
}
public bool CanExecute(object parameter)
{
return canExecute == null || (bool) canExecute.GetValue(viewModel, null);
}
public void Execute(object parameter)
{
object returnValue = execute.Invoke(viewModel, null);
if (returnValue != null)
HandleReturnValue(returnValue);
}
private static void HandleReturnValue(object returnValue)
{
var sequence = returnValue as IEnumerable<IAction>;
if (sequence != null)
Yield.Call(sequence);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.