Browse Source

Update CodeQuality/CodeQualityAnalysis.csproj to new references of ViewModelBase and RelayCommand.cs

pull/23/head
PeterForstmeier 14 years ago
parent
commit
b9d2322a30
  1. 2
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 2
      src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs
  3. 155
      src/AddIns/Analysis/CodeQuality/Src/Utility/RelayCommand.cs
  4. 80
      src/AddIns/Analysis/CodeQuality/Src/Utility/ViewModelBase.cs

2
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj

@ -149,8 +149,6 @@ @@ -149,8 +149,6 @@
<Compile Include="Src\Utility\Localizeable\EnumToFriendlyNameConverter.cs" />
<Compile Include="Src\Utility\Localizeable\LocalizableDescriptionAttribute.cs" />
<Compile Include="Src\Utility\Matrix.cs" />
<Compile Include="Src\Utility\RelayCommand.cs" />
<Compile Include="Src\Utility\ViewModelBase.cs" />
<Compile Include="Src\Utility\VisibleMatrix.cs" />
<Page Include="Resources\GridSplitterTemplate.xaml" />
<Page Include="Resources\GraphTemplate.xaml">

2
src/AddIns/Analysis/CodeQuality/Src/MainWindowModel.cs

@ -13,7 +13,7 @@ using System.Linq; @@ -13,7 +13,7 @@ using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using ICSharpCode.SharpDevelop.Widgets;
using ICSharpCode.CodeQualityAnalysis.Controls;
using ICSharpCode.CodeQualityAnalysis.Utility;
using ICSharpCode.CodeQualityAnalysis.Utility.Localizeable;

155
src/AddIns/Analysis/CodeQuality/Src/Utility/RelayCommand.cs

@ -1,155 +0,0 @@ @@ -1,155 +0,0 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 03.09.2011
* Time: 14:25
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Diagnostics;
using System.Windows.Input;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
public class RelayCommand<T> : ICommand
{
#region Declarations
readonly Predicate<T> _canExecute;
readonly Action<T> _execute;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class and the command can always be executed.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand(Action<T> execute)
: this(execute, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action<T> execute, Predicate<T> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add
{
if (_canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (_canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
[DebuggerStepThrough]
public Boolean CanExecute(Object parameter)
{
return _canExecute == null ? true : _canExecute((T)parameter);
}
public void Execute(Object parameter)
{
_execute((T)parameter);
}
#endregion
}
/// <summary>
/// A command whose sole purpose is to relay its functionality to other objects by invoking delegates. The default return value for the CanExecute method is 'true'.
/// </summary>
public class RelayCommand : ICommand
{
#region Declarations
readonly Func<Boolean> _canExecute;
readonly Action _execute;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class and the command can always be executed.
/// </summary>
/// <param name="execute">The execution logic.</param>
public RelayCommand(Action execute)
: this(execute, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RelayCommand&lt;T&gt;"/> class.
/// </summary>
/// <param name="execute">The execution logic.</param>
/// <param name="canExecute">The execution status logic.</param>
public RelayCommand(Action execute, Func<Boolean> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
#endregion
#region ICommand Members
public event EventHandler CanExecuteChanged
{
add
{
if (_canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (_canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
[DebuggerStepThrough]
public Boolean CanExecute(Object parameter)
{
return _canExecute == null ? true : _canExecute();
}
public void Execute(Object parameter)
{
_execute();
}
#endregion
}
}

80
src/AddIns/Analysis/CodeQuality/Src/Utility/ViewModelBase.cs

@ -1,80 +0,0 @@ @@ -1,80 +0,0 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 03.09.2011
* Time: 13:36
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace ICSharpCode.CodeQualityAnalysis.Utility
{
/// <summary>
/// Description of ViewModelBase.
/// </summary>
public class ViewModelBase:INotifyPropertyChanged
{
public ViewModelBase()
{
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
var handler = this.PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}
protected void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpresssion)
{
var propertyName = ExtractPropertyName(propertyExpresssion);
this.RaisePropertyChanged(propertyName);
}
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
private static String ExtractPropertyName<T>(Expression<Func<T>> propertyExpresssion)
{
if (propertyExpresssion == null)
{
throw new ArgumentNullException("propertyExpresssion");
}
var memberExpression = propertyExpresssion.Body as MemberExpression;
if (memberExpression == null)
{
throw new ArgumentException("The expression is not a member access expression.", "propertyExpresssion");
}
var property = memberExpression.Member as PropertyInfo;
if (property == null)
{
throw new ArgumentException("The member access expression does not access a property.", "propertyExpresssion");
}
var getMethod = property.GetGetMethod(true);
if (getMethod.IsStatic)
{
throw new ArgumentException("The referenced property is a static property.", "propertyExpresssion");
}
return memberExpression.Member.Name;
}
}
}
Loading…
Cancel
Save