static Func <object, T> GenerateConverterMethod(Type messageType) { UntypedChannel shunt = new ShuntChannel(); ParameterExpression value = Expression.Parameter(typeof(object), "value"); ConstantExpression shuntArg = Expression.Constant(shunt, typeof(UntypedChannel)); UnaryExpression castValue; if (typeof(T).IsValueType) { castValue = Expression.Convert(value, messageType); } else { castValue = Expression.TypeAs(value, messageType); } Type messageImplType = typeof(RequestImpl <>).MakeGenericType(messageType); ConstructorInfo constructorInfo = messageImplType.GetConstructor(new[] { typeof(UntypedChannel), messageType }); NewExpression constructor = Expression.New(constructorInfo, shuntArg, castValue); Expression <Func <object, T> > expression = Expression.Lambda <Func <object, T> >(constructor, value); return(expression.Compile()); }
protected override Channel <T> Visitor <T>(ShuntChannel <T> channel) { _current = GetVertex(channel.GetHashCode(), () => "Shunt", typeof(ShuntChannel <T>), typeof(T)); if (_stack.Count > 0) { _edges.Add(new Edge(_stack.Peek(), _current, _current.TargetType.Name)); } return(WithVertex(() => base.Visitor(channel))); }
protected override Channel <T> Visitor <T>(ChannelAdapter <T> channel) { Channel <T> output = channel.Output; if (_channels.Contains(output)) { var shunt = new ShuntChannel <T>(); channel.ChangeOutputChannel(output, shunt); _channels.Remove(output); } Channel <T> newOutput = Visit(output); if (newOutput != output) { channel.ChangeOutputChannel(output, newOutput); } return(channel); }
protected override Channel <T> Visitor <T>(ChannelAdapter <T> channel) { channel.ChangeOutputChannel(output => { Channel <T> replacement = output; if (_channels.Contains(output)) { replacement = new ShuntChannel <T>(); _channels.Remove(output); } Channel <T> newOutput = Visit(output); if (newOutput != output) { replacement = newOutput; } return(replacement); }); return(channel); }
protected override UntypedChannel Visitor(ChannelAdapter channel) { UntypedChannel original = channel.Output; UntypedChannel replacement = Visit(original); if (_channels.Contains(replacement)) { _channels.Remove(replacement); replacement = null; } if (replacement == null) { replacement = new ShuntChannel(); } if (replacement != original) { channel.ChangeOutputChannel(original, replacement); } return(channel); }
protected virtual Channel <T> Visitor <T>(ShuntChannel <T> channel) { return(channel); }
protected virtual UntypedChannel Visitor(ShuntChannel channel) { return(channel); }
protected override Channel <T> Visitor <T>(ShuntChannel <T> channel) { Trace.WriteLine("ShuntChannel<{0}>".FormatWith(typeof(T).Name)); return(base.Visitor <T>(channel)); }