Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 034dd8c

Browse files
committed
Use interface instead of base class
1 parent c7c0e80 commit 034dd8c

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

LibGit2Sharp/Core/LazyProperty.cs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,21 @@
44

55
namespace LibGit2Sharp.Core
66
{
7-
internal class LazyProperty<TType> : LazyPropertyBase
7+
internal class LazyProperty<TType> : IEvaluator<GitObjectSafeHandle>
88
{
9-
public LazyProperty(Func<GitObjectSafeHandle, object> evaluator, LazyGroup lazyGroup)
10-
: base(evaluator, lazyGroup)
11-
{ }
12-
13-
public TType Value
14-
{
15-
get { return (TType)base.Value; }
16-
}
17-
}
18-
19-
internal class LazyPropertyBase
20-
{
21-
private readonly Func<GitObjectSafeHandle, object> evaluator;
9+
private readonly Func<GitObjectSafeHandle, TType> evaluator;
2210
private readonly LazyGroup lazyGroup;
2311

24-
private object value;
12+
private TType value;
2513
private bool hasBeenEvaluated;
2614

27-
public LazyPropertyBase(Func<GitObjectSafeHandle, object> evaluator, LazyGroup lazyGroup)
15+
public LazyProperty(Func<GitObjectSafeHandle, TType> evaluator, LazyGroup lazyGroup)
2816
{
2917
this.evaluator = evaluator;
3018
this.lazyGroup = lazyGroup;
3119
}
3220

33-
public object Value
21+
public TType Value
3422
{
3523
get { return Evaluate(); }
3624
}
@@ -40,7 +28,7 @@ internal LazyGroup Group
4028
get { return lazyGroup; }
4129
}
4230

43-
private object Evaluate()
31+
private TType Evaluate()
4432
{
4533
if (!hasBeenEvaluated)
4634
{
@@ -56,27 +44,32 @@ private object Evaluate()
5644
return value;
5745
}
5846

59-
internal void InternalEvaluate(GitObjectSafeHandle objectPtr)
47+
void IEvaluator<GitObjectSafeHandle>.Evaluate(GitObjectSafeHandle objectPtr)
6048
{
6149
hasBeenEvaluated = true;
6250
value = evaluator(objectPtr);
6351
}
6452
}
6553

54+
internal interface IEvaluator<T>
55+
{
56+
void Evaluate(T input);
57+
}
58+
6659
internal class LazyGroup
6760
{
6861
private readonly Repository repo;
6962
private readonly ObjectId id;
7063

71-
private readonly IList<LazyPropertyBase> lazies = new List<LazyPropertyBase>();
64+
private readonly IList<IEvaluator<GitObjectSafeHandle>> lazies = new List<IEvaluator<GitObjectSafeHandle>>();
7265

7366
public LazyGroup(Repository repo, ObjectId id)
7467
{
7568
this.repo = repo;
7669
this.id = id;
7770
}
7871

79-
public LazyProperty<TType> AddLazy<TType>(Func<GitObjectSafeHandle, object> evaluator)
72+
public LazyProperty<TType> AddLazy<TType>(Func<GitObjectSafeHandle, TType> evaluator)
8073
{
8174
var lazy = new LazyProperty<TType>(evaluator, this);
8275
lazies.Add(lazy);
@@ -89,7 +82,7 @@ public void TriggerEvaluation()
8982
{
9083
foreach (var lazy in lazies)
9184
{
92-
lazy.InternalEvaluate(osw.ObjectPtr);
85+
lazy.Evaluate(osw.ObjectPtr);
9386
}
9487
}
9588
}

0 commit comments

Comments
 (0)