<#@ 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.06

using System;

namespace Xtensive.Core
{
  /// <summary>
  /// Extension methods for binding delegates to parameters.
  /// </summary>
  public static class DelegateBindExtensions
  {
<#
PushIndent("    ");
foreach (var delegateType in DelegateGenerator.GetDelegateTypes())
for (int total = 1; total <= DelegateGenerator.MaxNumberOfArguments; total++) {
  WriteLine("/// <summary>Binds first argument to specified delegate.</summary>");
  WriteLine("/// <returns> A delegate that takes the rest of arguments of original delegate.</returns>");
  Write("public static ");
  Write(DelegateGenerator.GenerateDelegate(delegateType, null, 2, total - 1));
  Write(" Bind");
  Write(DelegateGenerator.GenerateDelegateArguments(delegateType, null, 1, total));
  var firstArgument = string.Format("this {0} d", DelegateGenerator.GenerateDelegate(delegateType, null, 1, total));
  WriteLine(DelegateGenerator.GenerateArgumentDeclaration(firstArgument, 1, 1));
  WriteLine("{");
  PushIndent("  ");
  WriteLine("if (d==null) return null; // someone's dirty hack");
  Write("return ");
  Write(DelegateGenerator.GenerateArgumentUsage(null, 2, total-1));
  Write(" => d.Invoke");
  Write(DelegateGenerator.GenerateArgumentUsage(null, 1, total));
  WriteLine(";");
  PopIndent();
  WriteLine("}");
  WriteLine("");
}
PopIndent();
#>
  }
}
