コード例 #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);
     }
 }
コード例 #7
0
        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;
                }
            }
コード例 #9
0
        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)));
        }
コード例 #16
0
        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));
        }
コード例 #19
0
        private static object ParseStringForDateTimeOffset(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(new DateTimeOffset());
            }

            return(DateTimeOffset.Parse(
                       value,
                       CultureInfo.InvariantCulture,
                       DateTimeStyles.RoundtripKind));
        }
コード例 #20
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);
        }
コード例 #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;
                }
            }
コード例 #27
0
 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;
        }
コード例 #33
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;
        }
コード例 #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();
        }
コード例 #36
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;
        }
コード例 #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();
            }
        }
コード例 #39
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();
            }
        }
コード例 #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));
        }
コード例 #41
0
        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();
        }
コード例 #42
0
        private static object ParseStringForNullableGuid(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            return Guid.Parse(value);
        }
コード例 #43
0
        private static object ParseStringForNullableTimeSpan(string value, ISerializeOptions options)
        {
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }

            return TimeSpan.Parse(value, CultureInfo.InvariantCulture);
        }
コード例 #44
0
        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();
            }
        }
コード例 #47
0
 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;
        }
コード例 #49
0
 public string GetString(object value, ISerializeOptions options)
 {
     return _getString(value, options);
 }
コード例 #50
0
 private static string GetStringFromTimeSpan(object value, ISerializeOptions options)
 {
     var timeSpan = (TimeSpan)value;
     return timeSpan.ToString("G");
 }
コード例 #51
0
 private static string GetStringFromDateTimeOffset(object value, ISerializeOptions options)
 {
     var dateTimeOffset = (DateTimeOffset)value;
     return dateTimeOffset.ToString("O");
 }
コード例 #52
0
 public object ParseString(string value, ISerializeOptions options)
 {
     return _parseString(value, options);
 }
コード例 #53
0
 private static string GetStringFromBool(object value, ISerializeOptions options)
 {
     return value.ToString().ToLower();
 }
コード例 #54
0
        private static string GetStringFromChar(object value, ISerializeOptions options)
        {
            if (options.ShouldSerializeCharAsInt)
            {
                value = (int)(char)value;
            }

            return value.ToString();
        }
コード例 #55
0
 private static string GetStringFromNullableDateTimeOffset(object value, ISerializeOptions options)
 {
     return value == null ? null : GetStringFromDateTimeOffset(value, options);
 }
コード例 #56
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);
        }
コード例 #57
0
 private static string GetStringFromNullableTimeSpan(object value, ISerializeOptions options)
 {
     return value == null ? null : GetStringFromTimeSpan(value, options);
 }
コード例 #58
0
 private static object ParseStringForNullableBool(string value, ISerializeOptions options)
 {
     return string.IsNullOrEmpty(value) ? null : ParseStringForBool(value, options);
 }
コード例 #59
0
        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));
        }
コード例 #60
0
 public XSerializerXmlTextWriter(TextWriter writer, ISerializeOptions options)
     : this(new EncryptingTextWriter(writer, options.GetEncryptionMechanism(), options.EncryptKey, options.SerializationState), options)
 {
 }