Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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)));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 protected virtual Channel <T> Visitor <T>(ShuntChannel <T> channel)
 {
     return(channel);
 }
Ejemplo n.º 7
0
 protected virtual UntypedChannel Visitor(ShuntChannel channel)
 {
     return(channel);
 }
Ejemplo n.º 8
0
        protected override Channel <T> Visitor <T>(ShuntChannel <T> channel)
        {
            Trace.WriteLine("ShuntChannel<{0}>".FormatWith(typeof(T).Name));

            return(base.Visitor <T>(channel));
        }