refactoring
This commit is contained in:
parent
da6b68ea8f
commit
92bcc700ae
3 changed files with 34 additions and 2 deletions
|
|
@ -43,6 +43,8 @@
|
||||||
<Compile Include="Constants.cs" />
|
<Compile Include="Constants.cs" />
|
||||||
<Compile Include="Factories\ViewFactory.cs" />
|
<Compile Include="Factories\ViewFactory.cs" />
|
||||||
<Compile Include="Helpers\DataManager.cs" />
|
<Compile Include="Helpers\DataManager.cs" />
|
||||||
|
<Compile Include="Helpers\ObservableString.cs" />
|
||||||
|
<Compile Include="Interfaces\ILocalEntity.cs" />
|
||||||
<Compile Include="Helpers\LocaLEntity.cs" />
|
<Compile Include="Helpers\LocaLEntity.cs" />
|
||||||
<Compile Include="Helpers\NotIdentifiedException.cs" />
|
<Compile Include="Helpers\NotIdentifiedException.cs" />
|
||||||
<Compile Include="Helpers\PageHelpers.cs" />
|
<Compile Include="Helpers\PageHelpers.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,23 @@
|
||||||
|
|
||||||
|
using BookAStar.Interfaces;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace BookAStar
|
namespace BookAStar
|
||||||
{
|
{
|
||||||
public class LocalEntity<V, K> : ObservableCollection<V> where K : IEquatable<K>
|
public class LocalEntity<V, K> : ObservableCollection<V>, ILocalEntity<V, K> where K : IEquatable<K>
|
||||||
{
|
{
|
||||||
public V CurrentItem { get; protected set; }
|
public V CurrentItem { get; protected set; }
|
||||||
protected Func<V, K> GetKey { get; set; }
|
public Func<V, K> GetKey { get; set; }
|
||||||
public LocalEntity(Func<V, K> getKey) : base()
|
public LocalEntity(Func<V, K> getKey) : base()
|
||||||
{
|
{
|
||||||
if (getKey == null) throw new InvalidOperationException();
|
if (getKey == null) throw new InvalidOperationException();
|
||||||
GetKey = getKey;
|
GetKey = getKey;
|
||||||
|
IList<V> l = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Merge(V item)
|
public virtual void Merge(V item)
|
||||||
{
|
{
|
||||||
var key = GetKey(item);
|
var key = GetKey(item);
|
||||||
|
|
@ -29,6 +33,11 @@ namespace BookAStar
|
||||||
CurrentItem = this.Single(x => GetKey(x).Equals(key));
|
CurrentItem = this.Single(x => GetKey(x).Equals(key));
|
||||||
return CurrentItem;
|
return CurrentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
this.Populate<V>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
21
BookAStar/BookAStar/Interfaces/ILocalEntity.cs
Normal file
21
BookAStar/BookAStar/Interfaces/ILocalEntity.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace BookAStar
|
||||||
|
{
|
||||||
|
public interface ILoadable
|
||||||
|
{
|
||||||
|
void Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface ILocalEntity<V, K> : ILoadable where K : IEquatable<K>
|
||||||
|
{
|
||||||
|
V CurrentItem { get; }
|
||||||
|
|
||||||
|
Func<V, K> GetKey { get; set; }
|
||||||
|
|
||||||
|
V LocalGet(K key);
|
||||||
|
|
||||||
|
void Merge(V item);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue