<#@ output extension="cs"
#><#@ template language="C#"
#><#@ assembly name="System.Core"
#><#@ import namespace="System"
#><#@ import namespace="System.Linq"
#><#@ include file="..\..\DelegateGenerator.ttinclude"
#>// Copyright (C) 2003-2010 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Denis Krjuchkov
// Created:    2009.05.07

using System;
using System.Linq.Expressions;
using Xtensive.Linq;

namespace Xtensive.Core
{
  /// <summary>
  /// Extension methods for compiling strictly typed lambda expressions.
  /// </summary>
  public static class ExpressionCompileExtensions
  {
<#
PushIndent("    ");
foreach (var delegateType in DelegateGenerator.GetDelegateTypes())
for (int i = 0; i < DelegateGenerator.MaxNumberOfArguments; i++) {
  WriteLine("/// <summary>Compiles the specified lambda and caches the result of compilation.</summary>");
  WriteLine("/// <returns>Compiled lambda.</returns>");
  Write("public static ");
  Write(DelegateGenerator.GenerateDelegate(delegateType, null, 1, i));
  Write(" CachingCompile");
  Write(DelegateGenerator.GenerateDelegateArguments(delegateType, null, 1, i));
  Write("(this Expression<");
  Write(DelegateGenerator.GenerateDelegate(delegateType, null, 1, i));
  Write("> lambda");
  WriteLine(")");
  WriteLine("{");
  PushIndent("  ");
  WriteLine("var result = CachingExpressionCompiler.Instance.Compile(lambda);");
  Write("return ((");
  Write(DelegateGenerator.GenerateDelegate(delegateType, "object[]", 1, i));
  WriteLine(") result.First).Bind(result.Second);");
  PopIndent(); 
  WriteLine("}");
  WriteLine("");
}
PopIndent();
#>
  }
}