Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Extensions
- {
- public static string GetPropertyName<T>(this Expression<Func<T>> target)
- {
- var memberExpression = target.Body as MemberExpression;
- if (memberExpression == null)
- {
- UnaryExpression ubody = (UnaryExpression)target.Body;
- memberExpression = ubody.Operand as MemberExpression;
- }
- return memberExpression.Member.Name;
- }
- public static int ToInteger(this string target)
- {
- int val;
- if (int.TryParse(target, out val))
- return val;
- else
- return 0;
- }
- }
- public class IntToStringConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- return value.ToString();
- }
- public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
- {
- return (value as string).ToInteger();
- }
- }
- public class MainViewModel : INotifyPropertyChanged
- {
- public MainViewModel()
- {
- this.CalculateCommand = new RelayCommand(this.CalculateAction);
- }
- public ICommand CalculateCommand { get; private set; }
- private void CalculateAction()
- {
- int mid1 = this.UpperLimit - this.LowerLimit;
- int mid2 = (this.UpperLimit + this.LowerLimit) * 2;
- this.MidPoint = (mid1 * this.Function) * mid2;
- int trap1 = (this.UpperLimit - this.LowerLimit) * 2;
- int trap2 = (this.Function * this.UpperLimit) + (this.Function * this.LowerLimit);
- this.Trapezium = trap1 + trap2;
- this.Result = ((2 * this.MidPoint) + this.Trapezium) * 3;
- int stepedInt = (this.UpperLimit - this.LowerLimit) * this.Steps;
- }
- #region Fucking fields
- private int _function;
- private int _lowerLimit;
- private int _midPoint;
- private int _result;
- private int _steps;
- private int _trapezium;
- private int _upperLimit;
- #endregion Fucking fields
- #region Properties
- public int Function
- {
- get { return this._function; }
- set
- {
- if (this._function == value)
- return;
- this._function = value;
- this.RaiseNotifyPropertyChanged(() => this.Function);
- }
- }
- public int LowerLimit
- {
- get { return this._lowerLimit; }
- set
- {
- if (this._lowerLimit == value)
- return;
- this._lowerLimit = value;
- this.RaiseNotifyPropertyChanged(() => this.LowerLimit);
- }
- }
- public int MidPoint
- {
- get { return this._midPoint; }
- set
- {
- if (this._midPoint == value)
- return;
- this._midPoint = value;
- this.RaiseNotifyPropertyChanged(() => this.MidPoint);
- }
- }
- public int Result
- {
- get { return this._result; }
- set
- {
- if (this._result == value)
- return;
- this._result = value;
- this.RaiseNotifyPropertyChanged(() => this.Result);
- }
- }
- public int Steps
- {
- get { return this._steps; }
- set
- {
- if (this._steps == value)
- return;
- this._steps = value;
- this.RaiseNotifyPropertyChanged(() => this.Steps);
- }
- }
- public int Trapezium
- {
- get { return this._trapezium; }
- set
- {
- if (this._trapezium == value)
- return;
- this._trapezium = value;
- this.RaiseNotifyPropertyChanged(() => this.Trapezium);
- }
- }
- public int UpperLimit
- {
- get { return this._upperLimit; }
- set
- {
- if (this._upperLimit == value)
- return;
- this._upperLimit = value;
- this.RaiseNotifyPropertyChanged(() => this.UpperLimit);
- }
- }
- #endregion Properties
- #region INotifyPropertyChanged Implementation
- public event PropertyChangedEventHandler PropertyChanged;
- protected void RaiseNotifyPropertyChanged<T>(Expression<Func<T>> propertyExpression)
- {
- if (this.PropertyChanged != null)
- {
- string propertyName = propertyExpression.GetPropertyName();
- this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- #endregion INotifyPropertyChanged Implementation
- }
- public class RelayCommand : ICommand
- {
- public Action action;
- public Func<bool> canexecute;
- public RelayCommand(Action action, Func<bool> canexecute)
- {
- this.action = action;
- this.canexecute = canexecute;
- this.OnCanExecuteChanged();
- }
- public RelayCommand(Action action)
- {
- this.action = action;
- this.canexecute = () =>
- {
- return true;
- };
- this.OnCanExecuteChanged();
- }
- public event EventHandler CanExecuteChanged;
- public bool CanExecute(object parameter)
- {
- return this.canexecute();
- }
- public void Execute(object parameter)
- {
- this.action();
- }
- public void RefreshCanExecute()
- {
- this.OnCanExecuteChanged();
- }
- protected void OnCanExecuteChanged()
- {
- if (this.CanExecuteChanged != null)
- this.CanExecuteChanged(this, EventArgs.Empty);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement