private static void WriteGravatarRequestParam(XmlTextWriter writer, GravatarParameter par)
        {
            writer.WriteStartElement(GravatarConstants.XML_MEMBER);
            writer.WriteElementString(GravatarConstants.XML_NAME, par.Name);

            if (par.Type == GravatarParType.Array) {
                writer.WriteStartElement(GravatarConstants.XML_VALUE);
                writer.WriteStartElement(GravatarConstants.XML_ARRAY);
                writer.WriteStartElement(GravatarConstants.XML_DATA);

                foreach (var arrPar in par.ArrayValue) {
                    writer.WriteStartElement(GravatarConstants.XML_VALUE);

                    switch (arrPar.Type) {
                        case GravatarParType.Bool:
                            writer.WriteElementString(GravatarConstants.XML_BOOL, arrPar.StringValue);
                            break;
                        case GravatarParType.Integer:
                            writer.WriteElementString(GravatarConstants.XML_INT, arrPar.StringValue);
                            break;
                        default:
                            writer.WriteElementString(GravatarConstants.XML_STRING, arrPar.StringValue);
                            break;
                    }

                    writer.WriteEndElement(); //value
                }

                writer.WriteEndElement(); //data
                writer.WriteEndElement(); //array
                writer.WriteEndElement(); //value
            }
            else
            {
                writer.WriteElementString(GravatarConstants.XML_VALUE, par.StringValue);
            }

            writer.WriteEndElement(); //member
        }
        private GravatarParameter GetParameterFromXml(XContainer memberXml)
        {
            var par = new GravatarParameter();

            // set name
            var nameElm = memberXml.Element(GravatarConstants.XML_NAME);
            if (nameElm != null)
                par.Name = nameElm.Value;

            // set value
            var valType = memberXml.Element(GravatarConstants.XML_VALUE).Elements().First();
            if (valType.Name == GravatarConstants.XML_STRUCT) {
                par.Type = GravatarParType.Struct;
                par.StructValue = new GravatarStruct { Parameters = GetGravatarXmlMembers(valType) };
            } else if (valType.Name == GravatarConstants.XML_ARRAY) {
                par.Type = GravatarParType.Array;
                par.ArrayValue = from value in valType.Descendants(GravatarConstants.XML_VALUE) select GetParameterFromXml(value);
            } else if (valType.Name == GravatarConstants.XML_INT) {
                par.Type = GravatarParType.Integer;
                par.IntegerValue = int.Parse(valType.Value);
            } else if (valType.Name == GravatarConstants.XML_STRING) {
                par.Type = GravatarParType.String;
                par.StringValue = valType.Value;
            } else if (valType.Name == GravatarConstants.XML_BOOL || valType.Name == GravatarConstants.XML_BOOLEAN) {
                par.Type = GravatarParType.Bool;

                if (valType.Value == "1")
                    par.BooleanValue = true;
                else if (valType.Value == "0")
                    par.BooleanValue = false;
                else
                    par.BooleanValue = bool.Parse(valType.Value);
            }

            return par;
        }