Skip to content

Instantly share code, notes, and snippets.

View amoerie's full-sized avatar

Alexander Moerman amoerie

  • DOBCO Medical Systems
  • Belgium
View GitHub Profile
bind(Warrior.class).to(Samurai.class);
bind(Weapon.class).to(Nunchucks.class);
public interface Warrior {
void fight();
}
public class Ninja implements Warrior {
private Weapon weapon;
public Ninja(Weapon weapon) {
this.weapon = weapon;
bind(Warrior.class).to(Ninja.class);
public interface Warrior {
void fight();
}
public class Ninja implements Warrior {
@Override
public void fight() {
System.out.println("The ninja fights!");
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Wes.Core.Domain.Internal.Contracts;
namespace Wes.Core.Infrastructure.Utilities.Sorting
{
exec sp_executesql N'SELECT
[Project2].[Id1] AS [Id],
[Project2].[Id] AS [Id1],
[Project2].[C1] AS [C1],
[Project2].[Id2] AS [Id2],
[Project2].[CultureName] AS [CultureName],
[Project2].[ProductId] AS [ProductId],
[Project2].[Name] AS [Name]
FROM ( SELECT
[Extent1].[Id] AS [Id],
public static class Extensions
{
public static Expression<TDelegate> Expand<TDelegate> (this Expression<TDelegate> expr)
{
return (Expression<TDelegate>)new ReplacingExpressionsExpander().Visit(expr);
}
public static Expression Expand (this Expression expr)
{
return new ReplacingExpressionsExpander ().Visit (expr);
class ReplacingExpressionsExpander: ExpressionExpander
{
private static readonly IExpressionReplacer<MethodCallExpression>[] MethodCallReplacers
= new IExpressionReplacer<MethodCallExpression>[] {new ExpressionReplacerForExtensionsForITranslatableCurrent()};
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
{
foreach (var replacer in MethodCallReplacers.Where(replacer => replacer.ShouldReplace(methodCallExpression)))
{
return Visit(replacer.GetReplacement(methodCallExpression));
/// <summary>
/// Dynamically replaces a MethodCallExpression for 'ExtensionsForITranslatable.Current()' to
/// a valid equivalent expression
/// </summary>
public class ExpressionReplacerForExtensionsForITranslatableCurrent: IExpressionReplacer<MethodCallExpression>
{
private readonly MethodInfo _methodInfoForCurrent;
public ExpressionReplacerForExtensionsForITranslatableCurrent()
{
public interface IExpressionReplacer<in TExpression> where TExpression: Expression
{
bool ShouldReplace(TExpression expression);
Expression GetReplacement(TExpression expression);
}