This project has moved. For the latest updates, please go here.
1

Resolved

Wrong example in the performance documentation paragraph

description

In performance documentation paragraph, the following code is not correct as when an expression is not found in the cache, it is not added. This cause a new expression being created all the time instead of being returned from the cache.
A bracket is also missed.

Current Code:

var functionCache = new Dictionary<string, Func<object, object>> ();

public Func<object, object> GetCachedFunction(string expression)
{
Func<object, object> result;
if(!functionCache.TryGetValue(expression, out result)
{
  var exp = new CompiledExpression(expression);
  result = exp.ScopeCompile();
}
return result;
}

Proposed code:

var functionCache = new Dictionary<string, Func<object, object>> ();

public Func<object, object> GetCachedFunction(string expression)
{
Func<object, object> result;
if(!functionCache.TryGetValue(expression, out result))
{
  var exp = new CompiledExpression(expression);
  result = exp.ScopeCompile();
  functionCache.Add(expression, result);
}
return result;
}

Best regards,
Sebastiano Serri

comments

RupertAvery wrote Mar 1, 2016 at 11:03 PM

Thanks! I've updated the documentation.