public static XElement Serialize(this RuleAction action)
        {
            if (action is SqlRuleAction sqlRuleAction)
            {
                XElement parameterElement = null;
                if (sqlRuleAction.parameters != null)
                {
                    parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));
                    foreach (var param in sqlRuleAction.Parameters)
                    {
                        parameterElement.Add(
                            new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace),
                                         new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
                                         XmlObjectConvertor.SerializeObject(param.Value)));
                    }
                }

                return(new XElement(
                           XName.Get("Action", ManagementClientConstants.ServiceBusNamespace),
                           new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), nameof(SqlRuleAction)),
                           new XElement(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace), sqlRuleAction.SqlExpression),
                           parameterElement));
            }
            else
            {
                throw new NotImplementedException($"Rule action of type {action.GetType().Name} is not implemented");
            }
        }
        public static XElement Serialize(this SqlFilter filter, string filterName)
        {
            XElement parameterElement = null;

            if (filter.parameters != null)
            {
                parameterElement = new XElement(XName.Get("Parameters", ManagementClientConstants.ServiceBusNamespace));
                foreach (var param in filter.Parameters)
                {
                    parameterElement.Add(
                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace),
                                     new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
                                     XmlObjectConvertor.SerializeObject(param.Value)));
                }
            }

            return(new XElement(
                       XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
                       new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), filterName),
                       new XElement(XName.Get("SqlExpression", ManagementClientConstants.ServiceBusNamespace), filter.SqlExpression),
                       parameterElement));
        }
        public static XElement Serialize(this CorrelationFilter filter)
        {
            XElement parameterElement = null;

            if (filter.properties != null)
            {
                parameterElement = new XElement(XName.Get("Properties", ManagementClientConstants.ServiceBusNamespace));
                foreach (var param in filter.properties)
                {
                    parameterElement.Add(
                        new XElement(XName.Get("KeyValueOfstringanyType", ManagementClientConstants.ServiceBusNamespace),
                                     new XElement(XName.Get("Key", ManagementClientConstants.ServiceBusNamespace), param.Key),
                                     XmlObjectConvertor.SerializeObject(param.Value)));
                }
            }

            return(new XElement(
                       XName.Get("Filter", ManagementClientConstants.ServiceBusNamespace),
                       new XAttribute(XName.Get("type", ManagementClientConstants.XmlSchemaInstanceNamespace), nameof(CorrelationFilter)),
                       string.IsNullOrWhiteSpace(filter.CorrelationId) ? null :
                       new XElement(XName.Get("CorrelationId", ManagementClientConstants.ServiceBusNamespace), filter.CorrelationId),
                       string.IsNullOrWhiteSpace(filter.MessageId) ? null :
                       new XElement(XName.Get("MessageId", ManagementClientConstants.ServiceBusNamespace), filter.MessageId),
                       string.IsNullOrWhiteSpace(filter.To) ? null :
                       new XElement(XName.Get("To", ManagementClientConstants.ServiceBusNamespace), filter.To),
                       string.IsNullOrWhiteSpace(filter.ReplyTo) ? null :
                       new XElement(XName.Get("ReplyTo", ManagementClientConstants.ServiceBusNamespace), filter.ReplyTo),
                       string.IsNullOrWhiteSpace(filter.Label) ? null :
                       new XElement(XName.Get("Label", ManagementClientConstants.ServiceBusNamespace), filter.Label),
                       string.IsNullOrWhiteSpace(filter.SessionId) ? null :
                       new XElement(XName.Get("SessionId", ManagementClientConstants.ServiceBusNamespace), filter.SessionId),
                       string.IsNullOrWhiteSpace(filter.ReplyToSessionId) ? null :
                       new XElement(XName.Get("ReplyToSessionId", ManagementClientConstants.ServiceBusNamespace), filter.ReplyToSessionId),
                       string.IsNullOrWhiteSpace(filter.ContentType) ? null :
                       new XElement(XName.Get("ContentType", ManagementClientConstants.ServiceBusNamespace), filter.ContentType),
                       parameterElement));
        }