예제 #1
0
            public void SetElementPropertyValue(ISerializeOptions options, out bool shouldIssueRead)
            {
                SerializableProperty property;

                if (_caseSensitiveSerializableProperties.TryGetValue(_reader.Name, out property))
                {
                    var value = property.ReadValue(_reader, options);

                    if (_accumulatedValues.ContainsKey(property.Name.ToLower()))
                    {
                        var existingValue = _accumulatedValues[property.Name.ToLower()];
                        Combine(existingValue, value);
                    }
                    else
                    {
                        _accumulatedValues.Add(property.Name.ToLower(), value);
                    }

                    shouldIssueRead = !property.ReadsPastLastElement;
                }
                else
                {
                    shouldIssueRead = true;
                }
            }
예제 #2
0
 public void SetTextNodePropertyValue(ISerializeOptions options)
 {
     if (_textNodeProperty != null)
     {
         _textNodeProperty.ReadValue(_reader, _instance, options);
     }
 }
예제 #3
0
        public static void SerializeObject(
            this IXmlSerializerInternal serializer,
            Stream stream,
            object instance,
            Encoding encoding,
            Formatting formatting,
            ISerializeOptions options)
        {
            options = options.WithNewSerializationState();

            StreamWriter streamWriter = null;

            try
            {
                streamWriter = new StreamWriter(stream, encoding ?? Encoding.UTF8);

                var xmlWriter = new XSerializerXmlTextWriter(streamWriter, options)
                {
                    Formatting = formatting
                };

                serializer.SerializeObject(xmlWriter, instance, options);
                xmlWriter.Flush();
            }
            finally
            {
                if (streamWriter != null)
                {
                    streamWriter.Flush();
                }
            }
        }
예제 #4
0
        public object DeserializeObject(XSerializerXmlReader reader, ISerializeOptions options)
        {
            var isNil = reader.IsNil();

            if (isNil && reader.IsEmptyElement)
            {
                return(null);
            }

            object deserializedObject;

            var type = reader.GetXsdType <object>(_options.ExtraTypes);

            if (type != null)
            {
                var serializer = XmlSerializerFactory.Instance.GetSerializer(type, _encryptAttribute, _options.WithRootElementName(reader.Name));
                deserializedObject = serializer.DeserializeObject(reader, options);
            }
            else
            {
                deserializedObject = DeserializeToDynamic(reader, options);
            }

            return
                (isNil
                    ? null
                    : deserializedObject);
        }
예제 #5
0
        public object DeserializeObject(XSerializerXmlReader reader, ISerializeOptions options)
        {
            if (ValueTypes.IsRegistered(typeof(T)))
            {
                while (reader.NodeType != XmlNodeType.Element)
                {
                    reader.Read();
                }
            }

            if (reader.IsNil())
            {
                return(default(T));
            }

            var setIsDecryptionEnabledBackToFalse = reader.MaybeSetIsDecryptionEnabledToTrue(_encryptAttribute, options);

            var value = reader.ReadString();

            if (setIsDecryptionEnabledBackToFalse)
            {
                reader.IsDecryptionEnabled = false;
            }

            return(_valueConverter.ParseString(value, options));
        }
예제 #6
0
 public void WriteValue(XSerializerXmlTextWriter writer, object instance, ISerializeOptions options)
 {
     if (_shouldSerializeFunc(instance))
     {
         var value = _getValueFunc(instance);
         _serializer.Value.SerializeObject(writer, value, options);
     }
 }
        private static object ParseStringForTimeSpan(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(new TimeSpan());
            }

            return(TimeSpan.Parse(value, CultureInfo.InvariantCulture));
        }
예제 #8
0
            public void SetTextNodePropertyValue(ISerializeOptions options)
            {
                if (_textNodeProperty != null)
                {
                    var value = _textNodeProperty.ReadValue(_reader, options);

                    _accumulatedValues[_textNodeProperty.Name.ToLower()] = value;
                }
            }
        public object ParseString(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            return new Uri(value);
        }
예제 #10
0
        private static object ParseStringForNullableTimeSpan(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            return(TimeSpan.Parse(value, options.GetCulture()));
        }
예제 #11
0
        private static object ParseStringForNullableGuid(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            return(Guid.Parse(value));
        }
예제 #12
0
        private static string GetStringFromChar(object value, ISerializeOptions options)
        {
            if (options.ShouldSerializeCharAsInt)
            {
                value = (int)(char)value;
            }

            return(value.ToString());
        }
예제 #13
0
        public object ParseString(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            return(Type.GetType(value));
        }
예제 #14
0
            public void StageAttributeValue(ISerializeOptions options)
            {
                SerializableProperty property;

                if (_attributeProperties.TryGetValue(_reader.Name, out property))
                {
                    _setPropertyActions.Add(() => property.ReadValue(_reader, _instance, options));
                }
            }
예제 #15
0
        private static object ParseStringForChar(string value, ISerializeOptions options)
        {
            if (options.ShouldSerializeCharAsInt)
            {
                var charAsInt = ushort.Parse(value);
                return((char)charAsInt);
            }

            return((char)Convert.ChangeType(value, typeof(char)));
        }
        public string GetString(object value, ISerializeOptions options)
        {
            var returnValue = _decoratedValueConverter.GetString(value, options);

            if (options.ShouldEncrypt)
            {
                returnValue = _encryptionAlgorithm.Encrypt(returnValue);
            }

            return returnValue;
        }
예제 #17
0
        public string GetString(object value, ISerializeOptions options)
        {
            var returnValue = _decoratedValueConverter.GetString(value, options);

            if (options.ShouldEncrypt)
            {
                returnValue = _encryptionAlgorithm.Encrypt(returnValue);
            }

            return(returnValue);
        }
예제 #18
0
        private static object ParseStringForNullableDateTimeOffset(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            return(DateTimeOffset.Parse(
                       value,
                       options.GetCulture(),
                       DateTimeStyles.RoundtripKind));
        }
        private static object ParseStringForDateTimeOffset(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(new DateTimeOffset());
            }

            return(DateTimeOffset.Parse(
                       value,
                       CultureInfo.InvariantCulture,
                       DateTimeStyles.RoundtripKind));
        }
        public object ParseString(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            var enumTypeName = value.Substring(0, value.LastIndexOf('.'));
            var enumValue = value.Substring(value.LastIndexOf('.') + 1);

            var enumType = _enumExtraTypes.Single(t => t.Name == enumTypeName);
            return Enum.Parse(enumType, enumValue);
        }
예제 #21
0
        public object DeserializeObject(XSerializerXmlReader reader, ISerializeOptions options)
        {
            var setIsDecryptionEnabledBackToFalse = reader.MaybeSetIsDecryptionEnabledToTrue(_encryptAttribute, options);

            var value = _valueConverter.ParseString(reader.Value, options);

            if (setIsDecryptionEnabledBackToFalse)
            {
                reader.IsDecryptionEnabled = false;
            }

            return(value);
        }
예제 #22
0
        public object DeserializeObject(XSerializerXmlReader reader, ISerializeOptions options)
        {
            var setIsDecryptionEnabledBackToFalse = reader.MaybeSetIsDecryptionEnabledToTrue(_encryptAttribute, options);

            var value = _valueConverter.ParseString(reader.Value, options);

            if (setIsDecryptionEnabledBackToFalse)
            {
                reader.IsDecryptionEnabled = false;
            }

            return value;
        }
예제 #23
0
        public void SerializeObject(XSerializerXmlTextWriter writer, object value, ISerializeOptions options)
        {
            if (value != null)
            {
                var setIsEncryptionEnabledBackToFalse = writer.MaybeSetIsEncryptionEnabledToTrue(_encryptAttribute, options);

                writer.WriteValue(_valueConverter.GetString(value, options));

                if (setIsEncryptionEnabledBackToFalse)
                {
                    writer.IsEncryptionEnabled = false;
                }
            }
        }
예제 #24
0
        public void SerializeObject(XSerializerXmlTextWriter writer, object value, ISerializeOptions options)
        {
            if (value != null)
            {
                var setIsEncryptionEnabledBackToFalse = writer.MaybeSetIsEncryptionEnabledToTrue(_encryptAttribute, options);

                writer.WriteValue(_valueConverter.GetString(value, options));

                if (setIsEncryptionEnabledBackToFalse)
                {
                    writer.IsEncryptionEnabled = false;
                }
            }
        }
예제 #25
0
        public object ParseString(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }

            var enumTypeName = value.Substring(0, value.LastIndexOf('.'));
            var enumValue    = value.Substring(value.LastIndexOf('.') + 1);

            var enumType = _enumExtraTypes.Single(t => t.Name == enumTypeName);

            return(Enum.Parse(enumType, enumValue));
        }
예제 #26
0
            public void SetElementPropertyValue(ISerializeOptions options, out bool shouldIssueRead)
            {
                SerializableProperty property;

                if (_caseSensitiveSerializableProperties.TryGetValue(_reader.Name, out property))
                {
                    property.ReadValue(_reader, _instance, options);
                    shouldIssueRead = !property.ReadsPastLastElement;
                }
                else
                {
                    shouldIssueRead = true;
                }
            }
 private static ISerializeOptions WithNewSerializationState(this ISerializeOptions serializeOptions)
 {
     return(new SerializeOptions
     {
         EncryptionMechanism = serializeOptions.EncryptionMechanism,
         EncryptKey = serializeOptions.EncryptKey,
         Namespaces = serializeOptions.Namespaces,
         SerializationState = new SerializationState(),
         ShouldAlwaysEmitTypes = serializeOptions.ShouldAlwaysEmitTypes,
         ShouldEmitNil = serializeOptions.ShouldEmitNil,
         ShouldEncrypt = serializeOptions.ShouldEncrypt,
         ShouldRedact = serializeOptions.ShouldRedact,
         ShouldIgnoreCaseForEnum = serializeOptions.ShouldIgnoreCaseForEnum
     });
 }
예제 #28
0
            public void StageAttributeValue(ISerializeOptions options)
            {
                SerializableProperty property;

                if (_attributeProperties.TryGetValue(_reader.Name, out property))
                {
                    _setPropertyActions.Add(
                        () =>
                    {
                        var value = property.ReadValue(_reader, options);

                        _accumulatedValues[property.Name.ToLower()] = value;
                    });
                }
            }
예제 #29
0
        public void SerializeObject(XSerializerXmlTextWriter writer, object value, ISerializeOptions options)
        {
            var wasEmptyWriter = writer.IsEmpty;

            writer.WriteStartDocument();

            if (value != null)
            {
                WriteElement(writer, w => w.WriteValue(_valueConverter.GetString(value, options)), options);
            }
            else if (_alwaysEmitNil || options.ShouldEmitNil || wasEmptyWriter)
            {
                WriteElement(writer, w => w.WriteNilAttribute(), options);
            }
        }
예제 #30
0
        public string GetString(object value, ISerializeOptions options)
        {
            var type = value as Type;

            if (type == null)
            {
                return(null);
            }

            var typeString =
                _redactAttribute != null
                    ? _redactAttribute.Redact(type, options.ShouldRedact)
                    : GetStringValue(type);

            return(typeString);
        }
예제 #31
0
        public string GetString(object value, ISerializeOptions options)
        {
            var uri = value as Uri;

            if (uri == null)
            {
                return(null);
            }

            var uriString =
                _redactAttribute != null
                    ? _redactAttribute.Redact(uri, options.ShouldRedact)
                    : uri.ToString();

            return(uriString);
        }
예제 #32
0
        public string GetString(object value, ISerializeOptions options)
        {
            var uri = value as Uri;

            if (uri == null)
            {
                return null;
            }

            var uriString =
                _redactAttribute != null
                    ? _redactAttribute.Redact(uri, options.ShouldRedact)
                    : uri.ToString();

            return uriString;
        }
        public string GetString(object value, ISerializeOptions options)
        {
            var type = value as Type;

            if (type == null)
            {
                return null;
            }

            var typeString =
                _redactAttribute != null
                    ? _redactAttribute.Redact(type, options.ShouldRedact)
                    : GetStringValue(type);

            return typeString;
        }
예제 #34
0
        public void SerializeObject(XSerializerXmlTextWriter writer, object instance, ISerializeOptions options)
        {
            if (instance == null && !options.ShouldEmitNil)
            {
                return;
            }

            writer.WriteStartDocument();
            writer.WriteStartElement(_options.RootElementName);
            writer.WriteDefaultDocumentNamespaces();

            using (writer.WriteDefaultNamespace(_options.DefaultNamespace))
            {
                if (instance == null)
                {
                    writer.WriteNilAttribute();
                    writer.WriteEndElement();
                    return;
                }

                var setIsEncryptionEnabledBackToFalse = writer.MaybeSetIsEncryptionEnabledToTrue(_encryptAttribute, options);

                foreach (var item in GetDictionaryEntries(instance))
                {
                    writer.WriteStartElement("Item");

                    if (item.Key != null)
                    {
                        _keySerializer.SerializeObject(writer, item.Key, options);
                    }

                    if (item.Value != null)
                    {
                        _valueSerializer.SerializeObject(writer, item.Value, options);
                    }

                    writer.WriteEndElement();
                }

                if (setIsEncryptionEnabledBackToFalse)
                {
                    writer.IsEncryptionEnabled = false;
                }

                writer.WriteEndElement();
            }
        }
예제 #35
0
        public static void SerializeObject(
            this IXmlSerializerInternal serializer,
            TextWriter writer,
            object instance,
            Formatting formatting,
            ISerializeOptions options)
        {
            options = options.WithNewSerializationState();

            var xmlWriter = new XSerializerXmlTextWriter(writer, options)
            {
                Formatting = formatting
            };

            serializer.SerializeObject(xmlWriter, instance, options);
            xmlWriter.Flush();
        }
        public string GetString(object value, ISerializeOptions options)
        {
            var enumValue = value as Enum;

            if (enumValue == null)
            {
                return null;
            }

            var enumStringValue =
                _redactAttribute != null
                    ? _redactAttribute.Redact(enumValue, options.ShouldRedact)
                    : value.ToString();

            var combinedValue = value.GetType().Name + "." + enumStringValue;

            return combinedValue;
        }
예제 #37
0
        public string GetString(object value, ISerializeOptions options)
        {
            var enumValue = value as Enum;

            if (enumValue == null)
            {
                return(null);
            }

            var enumStringValue =
                _redactAttribute != null
                    ? _redactAttribute.Redact(enumValue, options.ShouldRedact)
                    : value.ToString();

            var combinedValue = value.GetType().Name + "." + enumStringValue;

            return(combinedValue);
        }
예제 #38
0
        public void SerializeObject(XSerializerXmlTextWriter writer, object value, ISerializeOptions options)
        {
            if (value != null)
            {
                writer.WriteStartAttribute(_attributeName); // TODO: include namespaces

                var setIsEncryptionEnabledBackToFalse = writer.MaybeSetIsEncryptionEnabledToTrue(_encryptAttribute, options);

                writer.WriteString(_valueConverter.GetString(value, options));

                if (setIsEncryptionEnabledBackToFalse)
                {
                    writer.IsEncryptionEnabled = false;
                }

                writer.WriteEndAttribute();
            }
        }
        public void SerializeObject(XSerializerXmlTextWriter writer, object value, ISerializeOptions options)
        {
            if (value != null)
            {
                writer.WriteStartAttribute(_attributeName); // TODO: include namespaces

                var setIsEncryptionEnabledBackToFalse = writer.MaybeSetIsEncryptionEnabledToTrue(_encryptAttribute, options);

                writer.WriteString(_valueConverter.GetString(value, options));

                if (setIsEncryptionEnabledBackToFalse)
                {
                    writer.IsEncryptionEnabled = false;
                }

                writer.WriteEndAttribute();
            }
        }
예제 #40
0
        private static object ParseStringForBool(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(default(bool));
            }

            if (value == "1")
            {
                return(true);
            }

            if (value == "0")
            {
                return(false);
            }

            return(Convert.ToBoolean(value));
        }
        public static string SerializeObject(
            this System.Xml.Serialization.XmlSerializer serializer,
            object instance,
            Encoding encoding,
            Formatting formatting,
            ISerializeOptions options)
        {
            
            var sb = new StringBuilder();
            using (var stringWriter = new StringWriterWithEncoding(sb, encoding ?? Encoding.UTF8))
            {
                using (var xmlWriter = new XSerializerXmlTextWriter(stringWriter, options))
                {
                    xmlWriter.Formatting = formatting;
                    serializer.Serialize(xmlWriter, instance, options.Namespaces);
                }
            }

            return sb.ToString();
        }
        private static object ParseStringForNullableGuid(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            return Guid.Parse(value);
        }
        private static object ParseStringForNullableTimeSpan(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            return TimeSpan.Parse(value, CultureInfo.InvariantCulture);
        }
        private static object ParseStringForNullableDateTimeOffset(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            return DateTimeOffset.Parse(
                value,
                CultureInfo.InvariantCulture,
                DateTimeStyles.RoundtripKind);
        }
예제 #45
0
        public object DeserializeObject(XSerializerXmlReader reader, ISerializeOptions options)
        {
            object collection = null;

            var hasInstanceBeenCreated = false;

            bool shouldIssueRead;

            var setIsDecryptionEnabledBackToFalse = false;

            if (_options.RootElementName == null)
            {
                setIsDecryptionEnabledBackToFalse = reader.MaybeSetIsDecryptionEnabledToTrue(_encryptAttribute, options);

                collection = _createCollection();
                hasInstanceBeenCreated = true;
            }

            do
            {
                shouldIssueRead = true;

                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (_options.RootElementName != null)
                        {
                            if (reader.Name == _options.RootElementName)
                            {
                                if (reader.IsNil())
                                {
                                    if (reader.IsEmptyElement)
                                    {
                                        return null;
                                    }

                                    collection = null;
                                    hasInstanceBeenCreated = true;
                                }
                                else
                                {
                                    setIsDecryptionEnabledBackToFalse = reader.MaybeSetIsDecryptionEnabledToTrue(_encryptAttribute, options);

                                    collection = _createCollection();
                                    hasInstanceBeenCreated = true;

                                    if (reader.IsEmptyElement)
                                    {
                                        if (setIsDecryptionEnabledBackToFalse)
                                        {
                                            reader.IsDecryptionEnabled = false;
                                        }

                                        return collection;
                                    }
                                }

                                break;
                            }
                        }
                        else
                        {
                            // If there's no root element, and we encounter another element, we're done - get out!
                            if (reader.Name != _itemElementName)
                            {
                                if (setIsDecryptionEnabledBackToFalse)
                                {
                                    reader.IsDecryptionEnabled = false;
                                }

                                return
                                    collection == null
                                        ? null
                                        : CheckAndReturn(hasInstanceBeenCreated, collection);
                            }
                        }

                        if (reader.Name == _itemElementName)
                        {
                            var item = DeserializeItem(reader, _itemSerializer, hasInstanceBeenCreated, options, out shouldIssueRead);

                            if (collection != null)
                            {
                                AddItemToCollection(collection, item);
                            }
                        }
                        break;
                    case XmlNodeType.EndElement:
                        if (_options.RootElementName != null)
                        {
                            if (reader.Name == _options.RootElementName)
                            {
                                if (setIsDecryptionEnabledBackToFalse)
                                {
                                    reader.IsDecryptionEnabled = false;
                                }

                                return
                                    collection == null
                                        ? null
                                        : CheckAndReturn(hasInstanceBeenCreated, collection);
                            }
                        }
                        else
                        {
                            if (reader.Name != _itemElementName)
                            {
                                if (setIsDecryptionEnabledBackToFalse)
                                {
                                    reader.IsDecryptionEnabled = false;
                                }

                                return
                                    collection == null
                                        ? null
                                        : CheckAndReturn(hasInstanceBeenCreated, collection);
                            }
                        }
                        break;
                }
            } while (reader.ReadIfNeeded(shouldIssueRead));

            throw new InvalidOperationException("Deserialization error: attempted to return a deserialized instance before it was created.");
        }
예제 #46
0
        public void SerializeObject(XSerializerXmlTextWriter writer, object instance, ISerializeOptions options)
        {
            if (instance == null && !options.ShouldEmitNil)
            {
                return;
            }

            if (_options.RootElementName != null)
            {
                writer.WriteStartDocument();
                writer.WriteStartElement(_options.RootElementName);
                writer.WriteDefaultDocumentNamespaces();
                writer.WriteDefaultNamespace(_options.DefaultNamespace).Dispose();
            }

            if (instance == null)
            {
                writer.WriteNilAttribute();
            }
            else
            {
                var setIsEncryptionEnabledBackToFalse = writer.MaybeSetIsEncryptionEnabledToTrue(_encryptAttribute, options);

                foreach (var item in (IEnumerable)instance)
                {
                    _itemSerializer.SerializeObject(writer, item, options);
                }

                if (setIsEncryptionEnabledBackToFalse)
                {
                    writer.IsEncryptionEnabled = false;
                }
            }

            if (_options.RootElementName != null)
            {
                writer.WriteEndElement();
            }
        }
 private XSerializerXmlTextWriter(EncryptingTextWriter encryptingTextWriter, ISerializeOptions options)
     : base(encryptingTextWriter)
 {
     _encryptingTextWriter = encryptingTextWriter;
     _options = options;
 }
예제 #48
0
        private static object DeserializeItem(XSerializerXmlReader reader, IXmlSerializerInternal serializer, bool hasInstanceBeenCreated, ISerializeOptions options, out bool shouldIssueRead)
        {
            if (!hasInstanceBeenCreated)
            {
                throw new InvalidOperationException("Deserialization error: attempted to deserialize an item before creating its list.");
            }

            var deserialized = serializer.DeserializeObject(reader, options);

            shouldIssueRead = true;

            return deserialized;
        }
 public string GetString(object value, ISerializeOptions options)
 {
     return _getString(value, options);
 }
 private static string GetStringFromTimeSpan(object value, ISerializeOptions options)
 {
     var timeSpan = (TimeSpan)value;
     return timeSpan.ToString("G");
 }
 private static string GetStringFromDateTimeOffset(object value, ISerializeOptions options)
 {
     var dateTimeOffset = (DateTimeOffset)value;
     return dateTimeOffset.ToString("O");
 }
 public object ParseString(string value, ISerializeOptions options)
 {
     return _parseString(value, options);
 }
 private static string GetStringFromBool(object value, ISerializeOptions options)
 {
     return value.ToString().ToLower();
 }
        private static string GetStringFromChar(object value, ISerializeOptions options)
        {
            if (options.ShouldSerializeCharAsInt)
            {
                value = (int)(char)value;
            }

            return value.ToString();
        }
 private static string GetStringFromNullableDateTimeOffset(object value, ISerializeOptions options)
 {
     return value == null ? null : GetStringFromDateTimeOffset(value, options);
 }
        private static object ParseStringForBool(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return default(bool);
            }

            if (value == "1")
            {
                return true;
            }

            if (value == "0")
            {
                return false;
            }

            return Convert.ToBoolean(value);
        }
 private static string GetStringFromNullableTimeSpan(object value, ISerializeOptions options)
 {
     return value == null ? null : GetStringFromTimeSpan(value, options);
 }
 private static object ParseStringForNullableBool(string value, ISerializeOptions options)
 {
     return string.IsNullOrEmpty(value) ? null : ParseStringForBool(value, options);
 }
        private static object ParseStringForNullableChar(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            if (options.ShouldSerializeCharAsInt)
            {
                var charAsInt = ushort.Parse(value);
                return (char)charAsInt;
            }

            return (char)Convert.ChangeType(value, typeof(char));
        }
 public XSerializerXmlTextWriter(TextWriter writer, ISerializeOptions options)
     : this(new EncryptingTextWriter(writer, options.GetEncryptionMechanism(), options.EncryptKey, options.SerializationState), options)
 {
 }