private void WriteXmlPrimitive(object o, XmlWriter xw, TypeDefinition def, string name = null, bool toEncrypt = false)
        {
            xw.WriteStartElement(name ?? def.PrimitiveName);
            var value = PrimitiveValueTools.SetPrimitiveValue(o, def);

            if (toEncrypt)
            {
                var algorithm = GetEncryptionAlgorithm();
                if (algorithm != null)
                {
                    value = algorithm.Encrypt(value);
                }
            }
            xw.WriteString(value);
            xw.WriteEndElement();
        }
        void WriteXmlPrimitive(object o, XmlWriter xw, TypeDefinition def, string name = null, bool toEncrypt = false,
                               string valueType = null)
        {
            xw.WriteStartElement(name ?? def.PrimitiveName);
            if (!string.IsNullOrEmpty(valueType))
            {
                xw.WriteAttributeString(Type, valueType);
            }
            var value = PrimitiveValueTools.SetPrimitiveValue(o, def);

            if (toEncrypt)
            {
                var algorithm = GetEncryptionAlgorithm();
                if (algorithm != null)
                {
                    value = algorithm.Encrypt(value);
                }
            }
            xw.WriteString(value);
            xw.WriteEndElement();
        }