예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected void MapXmlTypeData(object destination, IDbQueryResult source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _propertyName  = propertyDescriptor.GetName(false);
            var _propertyValue = source[propertyDescriptor.Prefix, _propertyName];

            if (ObjectUtils.IsXmlType(_propertyValue))
            {
                var _destination = propertyDescriptor.GetValue(destination)
                                   ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                var _serializer   = new DbQueryXmlSerializer(OperatingSession.OperationContext);
                var _descriptor   = OperatingSession.OperationContext.DescriptorManager.GetDescriptor(_destination);
                var _deserialized = _serializer.Deserialize(_propertyValue as XmlDocument, _descriptor.PropertyDescriptors, _destination);

                propertyDescriptor.SetValue(destination, _deserialized);
            }
            else if (propertyDescriptor.IsNullable)
            {
                var _destination = propertyDescriptor.GetValue(destination)
                                   ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);

                HandleReferenceTypeData(_destination, source);

                propertyDescriptor.SetValue(destination, _destination);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="propertyDescriptor"></param>
        /// <param name="destination"></param>
        protected void DeserializeReferenceTypeData(XmlNodeReader reader, DbQueryPropertyDescriptor propertyDescriptor, object destination)
        {
            if (CanDeserialize(reader) && CanDeserialize(propertyDescriptor))
            {
                if (ObjectUtils.IsListType(propertyDescriptor.RetrunType))
                {
                    var _destination     = (propertyDescriptor.GetValue(destination) as IList) ?? ObjectUtils.CreateInstanceOf <IList>(propertyDescriptor.RetrunType);
                    var _destiDescriptor = OperationContext.DescriptorManager.GetDescriptor(_destination);

                    Deserialize(reader, _destiDescriptor.PropertyDescriptors, _destination);

                    propertyDescriptor.SetValue(destination, _destination);
                }
                else
                {
                    var _parentName      = reader.Name;
                    var _destination     = propertyDescriptor.GetValue(destination) ?? ObjectUtils.CreateInstanceOf(propertyDescriptor.RetrunType);
                    var _destiDescriptor = OperationContext.DescriptorManager.GetDescriptor(_destination);

                    while (reader.Read())
                    {
                        if (!(reader.NodeType.Equals(XmlNodeType.EndElement) &&
                              _parentName.Equals(reader.Name, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            DeserializeValueTypeData(reader, _destiDescriptor.PropertyDescriptors, _destination);
                            continue;
                        }

                        propertyDescriptor.SetValue(destination, _destination);
                        break;
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="destination"></param>
        /// <param name="source"></param>
        /// <param name="propertyDescriptor"></param>
        protected virtual void MapValueTypeData(object destination, IDbQueryResult source, DbQueryPropertyDescriptor propertyDescriptor)
        {
            var _propertyName  = propertyDescriptor.GetName(false);
            var _propertyValue = _typeConverter.Convert(propertyDescriptor.RetrunType, source[propertyDescriptor.Prefix, _propertyName]);

            if (ObjectUtils.IsXmlType(_propertyValue) || !ObjectUtils.IsNullOrDefault(_propertyValue))
            {
                propertyDescriptor.SetValue(destination, _propertyValue);
            }
            else
            {
                if (!propertyDescriptor.IsNullable && !propertyDescriptor.IsReadOnly && null != propertyDescriptor.DefaultValue)
                {
                    _propertyValue = propertyDescriptor.GetValue(destination);

                    if (ObjectUtils.IsNullOrDefault(_propertyValue))
                    {
                        var _defaultValue = _typeConverter.Convert(propertyDescriptor.RetrunType, propertyDescriptor.DefaultValue);

                        propertyDescriptor.SetValue(destination, _defaultValue);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="propertyDescriptor"></param>
        /// <param name="destination"></param>
        protected void DeserializeValueTypeData(XmlNodeReader reader, DbQueryPropertyDescriptor propertyDescriptor, object destination)
        {
            if (CanDeserialize(reader) && CanDeserialize(propertyDescriptor))
            {
                reader.Read();

                if (reader.NodeType.Equals(XmlNodeType.Text) && reader.HasValue)
                {
                    var _value = _typeConverter.Convert(propertyDescriptor.RetrunType, reader.Value);

                    if (!ObjectUtils.IsNullOrDefault(_value))
                    {
                        propertyDescriptor.SetValue(destination, _value);
                    }
                }

                reader.Read();
            }
        }