public override MiddlewareParameter ToMiddlewareParam()
        {
            MiddlewareParameterDirection mwDirection = (MiddlewareParameterDirection)(int)Direction;
            List <MiddlewareParameter>   converted   = new List <MiddlewareParameter>();

            paramValue.ForEach(param => {
                StringParameter strParam = param as StringParameter;
                if (strParam != null)
                {
                    converted.Add(strParam.ToMiddlewareParam());
                }
                else
                {
                    ByteParameter byteParam = param as ByteParameter;
                    if (byteParam != null)
                    {
                        converted.Add(byteParam.ToMiddlewareParam());
                    }
                    else
                    {
                        MultiParameterResult multiParam = param as MultiParameterResult;
                        if (multiParam != null)
                        {
                            converted.Add(multiParam.ToMiddlewareParam());                            //down the rabbit hole we go
                        }
                    }
                }
            });
            return(new MiddlewareParameter <List <MiddlewareParameter> >(base.ParameterName, converted, mwDirection));
        }
        public static IEnumerable <ParameterBase> ConvertToOutput(this IEnumerable <MiddlewareParameter> middlewareParameters)
        {
            List <ParameterBase> results = new List <ParameterBase>();

            foreach (MiddlewareParameter current in middlewareParameters)
            {
                ParameterBase toAdd = null;
                MiddlewareParameter <string> strParameter = current as MiddlewareParameter <string>;
                if (strParameter != null)
                {
                    toAdd = new StringParameter(strParameter.ParamName, strParameter.ParamValue, ParameterDirection.Out);
                }
                else
                {
                    MiddlewareParameter <byte[]> byteParameter = current as MiddlewareParameter <byte[]>;
                    if (byteParameter != null)
                    {
                        //string value = MiddlewareConstants.EncodingInUse.GetString(byteParameter.ParamValue);
                        toAdd = new ByteParameter(byteParameter.ParamName, byteParameter.ParamValue, ParameterDirection.Out);
                    }
                    else if (current is MiddlewareParameter <Uri> )
                    {
                        MiddlewareParameter <Uri> uriParam = current as MiddlewareParameter <Uri>;
                        toAdd = new StringParameter(current.ParamName, uriParam.ParamValue.OriginalString, ParameterDirection.Out);
                        ((StringParameter)toAdd).IsUri = true;
                    }
                }
                if (toAdd == null)                //still hasn't managed
                {
                    MiddlewareParameter <List <MiddlewareParameter> > multiParam = current as MiddlewareParameter <List <MiddlewareParameter> >;
                    if (multiParam != null)
                    {
                        toAdd = new MultiParameterResult(multiParam.ParamName, (List <ParameterBase>)multiParam.ParamValue.ConvertToOutput(), ParameterDirection.Out);
                    }
                }
                if (toAdd == null)
                {
                    throw new InvalidOperationException("Parameter not of acceptable type");
                }
                results.Add(toAdd);
            }
            return(results);
        }