Cache property lookups for the object parsing

This commit is contained in:
2016-04-27 11:16:54 -04:00
parent 9730600164
commit 790930dd66
10 changed files with 185 additions and 58 deletions
@@ -0,0 +1,28 @@
using System;
using System.Reflection;
namespace LeafWeb.Core.Utility
{
public class ParseInfoPropertyMatcherWithCache<T> : ParseInfoPropertyMatcher<T>
where T: new()
{
private readonly Func<string, int, PropertyInfo> _matchPropertyMemo;
private readonly Func<string, int, PropertyInfo> _matchPropertyExactMemo;
public ParseInfoPropertyMatcherWithCache()
{
_matchPropertyMemo = Memoizer.ThreadsafeMemoize<string,int,PropertyInfo>(base.MatchProperty);
_matchPropertyExactMemo = Memoizer.ThreadsafeMemoize<string,int,PropertyInfo>(base.MatchPropertyExact);
}
public override PropertyInfo MatchProperty(string title, int position)
{
return _matchPropertyMemo(title, position);
}
public override PropertyInfo MatchPropertyExact(string title, int position)
{
return _matchPropertyExactMemo(title, position);
}
}
}