Added some documentation and cleaning up.

This commit is contained in:
Laurent Bugnion 2016-04-20 23:47:19 +02:00
Родитель e289bfaa29
Коммит c4eb36471e
11 изменённых файлов: 118 добавлений и 67 удалений

Просмотреть файл

@ -1,4 +1,19 @@
using System; // ****************************************************************************
// <copyright file="ObservableCollectionViewSource.cs" company="GalaSoft Laurent Bugnion">
// Copyright © GalaSoft Laurent Bugnion 2009-2016
// </copyright>
// ****************************************************************************
// <author>Laurent Bugnion</author>
// <email>laurent@galasoft.ch</email>
// <date>17.04.2016</date>
// <project>GalaSoft.MvvmLight</project>
// <web>http://www.mvvmlight.net</web>
// <license>
// See license.txt in this solution or http://www.galasoft.ch/license_MIT.txt
// </license>
// ****************************************************************************
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
@ -118,7 +133,7 @@ namespace GalaSoft.MvvmLight.Helpers
return _selectedItem; return _selectedItem;
} }
set protected set
{ {
if (Equals(_selectedItem, value)) if (Equals(_selectedItem, value))
{ {
@ -177,6 +192,16 @@ namespace GalaSoft.MvvmLight.Helpers
return cell; return cell;
} }
/// <summary>
/// Gets the item selected by the NSIndexPath passed as parameter.
/// </summary>
/// <param name="indexPath">The NSIndexPath pointing to the desired item.</param>
/// <returns>The item selected by the NSIndexPath passed as parameter.</returns>
public TItem GetItem(NSIndexPath indexPath)
{
return _dataSource[indexPath.Row];
}
/// <summary> /// <summary>
/// Overrides the <see cref="UICollectionViewSource.GetItemsCount"/> method. /// Overrides the <see cref="UICollectionViewSource.GetItemsCount"/> method.
/// Gets the number of items in the data source. /// Gets the number of items in the data source.
@ -278,16 +303,6 @@ namespace GalaSoft.MvvmLight.Helpers
BindCellDelegate((TCell)cell, (TItem)item, indexPath); BindCellDelegate((TCell)cell, (TItem)item, indexPath);
} }
/// <summary>
/// Gets the item selected by the NSIndexPath passed as parameter.
/// </summary>
/// <param name="indexPath">The NSIndexPath pointing to the desired item.</param>
/// <returns>The item selected by the NSIndexPath passed as parameter.</returns>
protected TItem GetItem(NSIndexPath indexPath)
{
return _dataSource[indexPath.Row];
}
/// <summary> /// <summary>
/// Raises the <see cref="PropertyChanged"/> event. /// Raises the <see cref="PropertyChanged"/> event.
/// </summary> /// </summary>

Просмотреть файл

@ -1,4 +1,19 @@
using System; // ****************************************************************************
// <copyright file="ObservableTableViewSource.cs" company="GalaSoft Laurent Bugnion">
// Copyright © GalaSoft Laurent Bugnion 2009-2016
// </copyright>
// ****************************************************************************
// <author>Laurent Bugnion</author>
// <email>laurent@galasoft.ch</email>
// <date>17.04.2016</date>
// <project>GalaSoft.MvvmLight</project>
// <web>http://www.mvvmlight.net</web>
// <license>
// See license.txt in this solution or http://www.galasoft.ch/license_MIT.txt
// </license>
// ****************************************************************************
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
@ -175,7 +190,7 @@ namespace GalaSoft.MvvmLight.Helpers
return _selectedItem; return _selectedItem;
} }
set protected set
{ {
if (Equals(_selectedItem, value)) if (Equals(_selectedItem, value))
{ {
@ -276,6 +291,16 @@ namespace GalaSoft.MvvmLight.Helpers
return 0; return 0;
} }
/// <summary>
/// Gets the item selected by the NSIndexPath passed as parameter.
/// </summary>
/// <param name="indexPath">The NSIndexPath pointing to the desired item.</param>
/// <returns>The item selected by the NSIndexPath passed as parameter.</returns>
public TItem GetItem(NSIndexPath indexPath)
{
return _dataSource[indexPath.Row];
}
/// <summary> /// <summary>
/// When called, checks if the <see cref="GetViewForFooterDelegate"/> /// When called, checks if the <see cref="GetViewForFooterDelegate"/>
/// delegate has been set. If yes, calls that delegate to get the TableView's footer. /// delegate has been set. If yes, calls that delegate to get the TableView's footer.
@ -400,16 +425,6 @@ namespace GalaSoft.MvvmLight.Helpers
return CreateCellDelegate(reuseId); return CreateCellDelegate(reuseId);
} }
/// <summary>
/// Gets the item selected by the NSIndexPath passed as parameter.
/// </summary>
/// <param name="indexPath">The NSIndexPath pointing to the desired item.</param>
/// <returns>The item selected by the NSIndexPath passed as parameter.</returns>
protected TItem GetItem(NSIndexPath indexPath)
{
return _dataSource[indexPath.Row];
}
/// <summary> /// <summary>
/// Raises the <see cref="PropertyChanged"/> event. /// Raises the <see cref="PropertyChanged"/> event.
/// </summary> /// </summary>

Просмотреть файл

@ -31,8 +31,6 @@ namespace GalaSoft.MvvmLight.Views
////[ClassInfo(typeof(INavigationService))] ////[ClassInfo(typeof(INavigationService))]
public class NavigationService : INavigationService public class NavigationService : INavigationService
{ {
private readonly Dictionary<WeakReference, object> _parametersByController = new Dictionary<WeakReference, object>();
/// <summary> /// <summary>
/// The key that is returned by the <see cref="CurrentPageKey"/> property /// The key that is returned by the <see cref="CurrentPageKey"/> property
/// when the current UIViewController is the root controller. /// when the current UIViewController is the root controller.
@ -49,43 +47,8 @@ namespace GalaSoft.MvvmLight.Views
private readonly Dictionary<string, TypeActionOrKey> _pagesByKey = new Dictionary<string, TypeActionOrKey>(); private readonly Dictionary<string, TypeActionOrKey> _pagesByKey = new Dictionary<string, TypeActionOrKey>();
/// <summary> private readonly Dictionary<WeakReference, object> _parametersByController =
/// Allows a caller to get the navigation parameter corresponding new Dictionary<WeakReference, object>();
/// to the Intent parameter.
/// </summary>
/// <param name="controller">The <see cref="UIViewController"/> that was navigated to.</param>
/// <returns>The navigation parameter. If no parameter is found,
/// returns null.</returns>
public object GetAndRemoveParameter(UIViewController controller)
{
if (controller == null)
{
throw new ArgumentNullException("controller", "This method must be called with a valid UIViewController");
}
lock (_parametersByController)
{
object value = null;
WeakReference key = null;
foreach (var pair in _parametersByController)
{
if (Equals(pair.Key.Target, controller))
{
key = pair.Key;
value = pair.Value;
break;
}
}
if (key != null)
{
_parametersByController.Remove(key);
}
return value;
}
}
/// <summary> /// <summary>
/// The key corresponding to the currently displayed page. /// The key corresponding to the currently displayed page.
@ -188,6 +151,46 @@ namespace GalaSoft.MvvmLight.Views
SaveConfigurationItem(key, item); SaveConfigurationItem(key, item);
} }
/// <summary>
/// Allows a caller to get the navigation parameter corresponding
/// to the Intent parameter.
/// </summary>
/// <param name="controller">The <see cref="UIViewController"/> that was navigated to.</param>
/// <returns>The navigation parameter. If no parameter is found,
/// returns null.</returns>
public object GetAndRemoveParameter(UIViewController controller)
{
if (controller == null)
{
throw new ArgumentNullException(
"controller",
"This method must be called with a valid UIViewController");
}
lock (_parametersByController)
{
object value = null;
WeakReference key = null;
foreach (var pair in _parametersByController)
{
if (Equals(pair.Key.Target, controller))
{
key = pair.Key;
value = pair.Value;
break;
}
}
if (key != null)
{
_parametersByController.Remove(key);
}
return value;
}
}
/// <summary> /// <summary>
/// If possible, discards the current page and displays the previous page /// If possible, discards the current page and displays the previous page
/// on the navigation stack. /// on the navigation stack.

Просмотреть файл

@ -6,6 +6,9 @@ using Android.Widget;
namespace GalaSoft.MvvmLight.Test.Controls namespace GalaSoft.MvvmLight.Test.Controls
{ {
/// <summary>
/// Extending the Button control for unit test purposes (triggering events).
/// </summary>
public class ButtonEx : Button public class ButtonEx : Button
{ {
public ButtonEx(IntPtr javaReference, JniHandleOwnership transfer) public ButtonEx(IntPtr javaReference, JniHandleOwnership transfer)

Просмотреть файл

@ -34,7 +34,7 @@
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath> <OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE;ANDROID</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime> <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>

Просмотреть файл

@ -1,5 +1,8 @@
namespace GalaSoft.MvvmLight.Test.ViewModel namespace GalaSoft.MvvmLight.Test.ViewModel
{ {
/// <summary>
/// Test class used for Unit test purposes.
/// </summary>
public class AccountModel : ObservableObject public class AccountModel : ObservableObject
{ {
private string _name = "Account name"; private string _name = "Account name";

Просмотреть файл

@ -1,5 +1,8 @@
namespace GalaSoft.MvvmLight.Test.ViewModel namespace GalaSoft.MvvmLight.Test.ViewModel
{ {
/// <summary>
/// Test class used for Unit test purposes.
/// </summary>
public class AccountViewModel : ViewModelBase public class AccountViewModel : ViewModelBase
{ {
public const string EmptyText = "Empty"; public const string EmptyText = "Empty";

Просмотреть файл

@ -3,6 +3,9 @@ using System.Windows.Input;
namespace GalaSoft.MvvmLight.Test.ViewModel namespace GalaSoft.MvvmLight.Test.ViewModel
{ {
/// <summary>
/// Test class used for Unit test purposes.
/// </summary>
public class CommandImpl : ICommand public class CommandImpl : ICommand
{ {
private readonly string _initialValue; private readonly string _initialValue;

Просмотреть файл

@ -1,10 +1,12 @@
#if __IOS__ #if __IOS__
using Foundation; using Foundation;
#endif #endif
namespace GalaSoft.MvvmLight.Test.ViewModel namespace GalaSoft.MvvmLight.Test.ViewModel
{ {
/// <summary>
/// Test class used for Unit test purposes.
/// </summary>
public class TestItem public class TestItem
{ {
public TestItem(string title) public TestItem(string title)

Просмотреть файл

@ -1,5 +1,8 @@
namespace GalaSoft.MvvmLight.Test.ViewModel namespace GalaSoft.MvvmLight.Test.ViewModel
{ {
/// <summary>
/// Test class used for Unit test purposes.
/// </summary>
public class TestModel : ObservableObject public class TestModel : ObservableObject
{ {
private string _myProperty; private string _myProperty;

Просмотреть файл

@ -6,19 +6,20 @@ using GalaSoft.MvvmLight.Command;
namespace GalaSoft.MvvmLight.Test.ViewModel namespace GalaSoft.MvvmLight.Test.ViewModel
{ {
/// <summary>
/// Test class used for Unit test purposes.
/// </summary>
public class TestViewModel : ViewModelBase public class TestViewModel : ViewModelBase
{ {
public const string ValueForCommand = "Command value"; public const string ValueForCommand = "Command value";
private bool _boolProperty; private bool _boolProperty;
private DateTime _date; private DateTime _date;
private TestModel _model; private TestModel _model;
private TestViewModel _nested; private TestViewModel _nested;
private string _propertyValue; private string _propertyValue;
private RelayCommand<string> _setPropertyCommand; private RelayCommand<string> _setPropertyCommand;
private RelayCommand _setPropertyWithoutValueCommand; private RelayCommand _setPropertyWithoutValueCommand;
private string _targetPropertyObservable; private string _targetPropertyObservable;
private ICommand _testCommandImpl; private ICommand _testCommandImpl;