Skip to content

Commit

Permalink
C# 7 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Jun 9, 2017
1 parent 5127b59 commit 2c3dadc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 37 deletions.
28 changes: 14 additions & 14 deletions MvvmHelpers/BaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class BaseViewModel : ObservableObject
/// <value>The title.</value>
public string Title
{
get { return title; }
set { SetProperty(ref title, value); }
get => title;
set => SetProperty(ref title, value);
}

string subtitle = string.Empty;
Expand All @@ -25,8 +25,8 @@ public string Title
/// <value>The subtitle.</value>
public string Subtitle
{
get { return subtitle; }
set { SetProperty(ref subtitle, value); }
get => subtitle;
set => SetProperty(ref subtitle, value);
}

string icon = string.Empty;
Expand All @@ -37,8 +37,8 @@ public string Subtitle
/// <value>The icon.</value>
public string Icon
{
get { return icon; }
set { SetProperty(ref icon, value); }
get => icon;
set => SetProperty(ref icon, value);
}

bool isBusy;
Expand All @@ -49,7 +49,7 @@ public string Icon
/// <value><c>true</c> if this instance is busy; otherwise, <c>false</c>.</value>
public bool IsBusy
{
get { return isBusy; }
get => isBusy;
set
{
if (SetProperty(ref isBusy, value))
Expand All @@ -65,7 +65,7 @@ public bool IsBusy
/// <value><c>true</c> if this instance is not busy; otherwise, <c>false</c>.</value>
public bool IsNotBusy
{
get { return isNotBusy; }
get => isNotBusy;
set
{
if(SetProperty(ref isNotBusy, value))
Expand All @@ -81,8 +81,8 @@ public bool IsNotBusy
/// <value><c>true</c> if this instance can load more; otherwise, <c>false</c>.</value>
public bool CanLoadMore
{
get { return canLoadMore; }
set { SetProperty(ref canLoadMore, value); }
get => canLoadMore;
set => SetProperty(ref canLoadMore, value);
}


Expand All @@ -94,8 +94,8 @@ public bool CanLoadMore
/// <value>The header.</value>
public string Header
{
get { return header; }
set { SetProperty(ref header, value); }
get => header;
set => SetProperty(ref header, value);
}

string footer = string.Empty;
Expand All @@ -106,8 +106,8 @@ public string Header
/// <value>The footer.</value>
public string Footer
{
get { return footer; }
set { SetProperty(ref footer, value); }
get => footer;
set => SetProperty(ref footer, value);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions MvvmHelpers/Grouping.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Collections.Generic;

namespace MvvmHelpers
{
Expand All @@ -12,7 +11,7 @@ public class Grouping<TKey, TItem> : ObservableRangeCollection<TItem>
/// Gets the key.
/// </summary>
/// <value>The key.</value>
public TKey Key { get; private set; }
public TKey Key { get; }

/// <summary>
/// Returns list of items in the grouping.
Expand Down Expand Up @@ -41,12 +40,12 @@ public class Grouping<TKey, TSubKey, TItem> : ObservableRangeCollection<TItem>
/// Gets the key.
/// </summary>
/// <value>The key.</value>
public TKey Key { get; private set; }
public TKey Key { get; }

/// <summary>
/// Gets the subkey of the grouping
/// </summary>
public TSubKey SubKey { get; private set; }
public TSubKey SubKey { get; }

/// <summary>
/// Returns list of items in the grouping.
Expand Down
2 changes: 1 addition & 1 deletion MvvmHelpers/ObservableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ObservableObject : INotifyPropertyChanged
/// <param name="propertyName">Property name.</param>
/// <param name="onChanged">On changed.</param>
/// <typeparam name="T">The 1st type parameter.</typeparam>
protected bool SetProperty<T>(
protected virtual bool SetProperty<T>(
ref T backingStore, T value,
[CallerMemberName]string propertyName = "",
Action onChanged = null)
Expand Down
18 changes: 6 additions & 12 deletions MvvmHelpers/ObservableRangeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ public ObservableRangeCollection(IEnumerable<T> collection)
public void AddRange(IEnumerable<T> collection, NotifyCollectionChangedAction notificationMode = NotifyCollectionChangedAction.Add)
{
if (notificationMode != NotifyCollectionChangedAction.Add && notificationMode != NotifyCollectionChangedAction.Reset)
throw new ArgumentException("Mode must be either Add or Reset for AddRange.", "notificationMode");
throw new ArgumentException("Mode must be either Add or Reset for AddRange.", nameof(notificationMode));
if (collection == null)
throw new ArgumentNullException("collection");
throw new ArgumentNullException(nameof(collection));

CheckReentrancy();

if (notificationMode == NotifyCollectionChangedAction.Reset)
{
foreach (var i in collection)
{
Items.Add(i);
}

OnPropertyChanged(new PropertyChangedEventArgs("Count"));
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
Expand All @@ -61,9 +59,7 @@ public void AddRange(IEnumerable<T> collection, NotifyCollectionChangedAction no
int startIndex = Count;
var changedItems = collection is List<T> ? (List<T>)collection : new List<T>(collection);
foreach (var i in changedItems)
{
Items.Add(i);
}

OnPropertyChanged(new PropertyChangedEventArgs("Count"));
OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
Expand All @@ -76,9 +72,9 @@ public void AddRange(IEnumerable<T> collection, NotifyCollectionChangedAction no
public void RemoveRange(IEnumerable<T> collection, NotifyCollectionChangedAction notificationMode = NotifyCollectionChangedAction.Reset)
{
if (notificationMode != NotifyCollectionChangedAction.Remove && notificationMode != NotifyCollectionChangedAction.Reset)
throw new ArgumentException("Mode must be either Remove or Reset for RemoveRange.", "notificationMode");
throw new ArgumentException("Mode must be either Remove or Reset for RemoveRange.", nameof(notificationMode));
if (collection == null)
throw new ArgumentNullException("collection");
throw new ArgumentNullException(nameof(collection));

CheckReentrancy();

Expand All @@ -87,6 +83,7 @@ public void RemoveRange(IEnumerable<T> collection, NotifyCollectionChangedAction

foreach (var i in collection)
Items.Remove(i);

OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

return;
Expand All @@ -110,10 +107,7 @@ public void RemoveRange(IEnumerable<T> collection, NotifyCollectionChangedAction
/// <summary>
/// Clears the current collection and replaces it with the specified item.
/// </summary>
public void Replace(T item)
{
ReplaceRange(new T[] { item });
}
public void Replace(T item) => ReplaceRange(new T[] { item });

/// <summary>
/// Clears the current collection and replaces it with the specified collection.
Expand Down
5 changes: 1 addition & 4 deletions MvvmHelpers/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public async static Task<T> WithTimeout<T>(this Task<T> task, int timeoutInMilli
var retTask = await Task.WhenAny(task, Task.Delay(timeoutInMilliseconds))
.ConfigureAwait(false);

if (retTask is Task<T>)
return task.Result;

return default(T);
return retTask is Task<T> ? task.Result : default(T);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Collection of MVVM helper classes for any application.


Grab the NuGet: https://www.nuget.org/packages/Refractored.MvvmHelpers

Build Status: [![Build status](https://ci.appveyor.com/api/projects/status/nsj9rae1g93hy62o/branch/master?svg=true)](https://ci.appveyor.com/project/JamesMontemagno/mvvm-helpers/branch/master)
Expand Down

0 comments on commit 2c3dadc

Please sign in to comment.