internal static void ReadTo(this XElement xe, IDictionary <string, object> dynamicObject, BindableDynamicObject.XmlSettings xmlSettings)
 {
     if (xmlSettings.IsImplicit())
     {
         xe.ReadAttributes(dynamicObject);
         xe.ReadElements(dynamicObject, xmlSettings);
     }
     else
     if (xmlSettings.SerializePropertyAsAttribute)
     {
         xe.ReadAttributes(dynamicObject);
     }
     else
     {
         xe.ReadElements(dynamicObject, xmlSettings);
     }
 }
        internal static object ReadValue(this XElement xe, BindableDynamicObject.XmlSettings xmlSettings)
        {
            if ((bool?)xe.Attribute(XnNil) ?? false)
            {
                return(null);
            }

            string declaredType = null;

            switch (xmlSettings.TypeSchema)
            {
            case BindableDynamicObject.XmlSettings.DataTypeSchema.Xsd:
                declaredType = xe.GetXsdTypeAttributeString();
                if (string.IsNullOrEmpty(declaredType))
                {
                    if (xmlSettings.IsImplicit())
                    {
                        declaredType = xe.GetNetTypeAttributeString();
                    }
                }
                else
                {
                    try { return(_XsdDataContractSerializer.ReadObject(xe.CreateReader(), false)); }
                    catch { }
                }
                break;

            case BindableDynamicObject.XmlSettings.DataTypeSchema.Net:
                declaredType = xe.GetNetTypeAttributeString();
                if (declaredType == null && xmlSettings.IsImplicit())
                {
                    declaredType = xe.GetXsdTypeAttributeString();
                }
                break;

            default:
                if (xmlSettings.IsImplicit())
                {
                    declaredType = xe.GetXsdTypeAttributeString();
                    if (string.IsNullOrEmpty(declaredType))
                    {
                        declaredType = xe.GetNetTypeAttributeString();
                    }
                    else
                    {
                        try { return(_XsdDataContractSerializer.ReadObject(xe.CreateReader(), false)); }
                        catch { }
                    }
                }
                break;
            }

            Type valueType = GetXsdType(declaredType);

            if (valueType == typeof(string))
            {
                return(xe.Value);
            }

            try
            {
                return(DBConvert.ChangeType(xe.Value, valueType));
            }
            catch
            {
                return(xe.Value);
            }
        }
        internal static object ReadValue(this XmlReader reader, BindableDynamicObject.XmlSettings xmlSettings)
        {
            if (reader.IsNilElement())
            {
                reader.Skip();
                return(null);
            }

            string declaredType = null;

            switch (xmlSettings.TypeSchema)
            {
            case BindableDynamicObject.XmlSettings.DataTypeSchema.Xsd:
                declaredType = reader.GetAttribute(XsdTypeAttributeName, XmlSchema.InstanceNamespace);
                if (string.IsNullOrEmpty(declaredType))
                {
                    if (xmlSettings.IsImplicit())
                    {
                        declaredType = reader.GetAttribute(NetTypeAttributeName, NsNet);
                        if (!string.IsNullOrEmpty(declaredType))
                        {
                            return(_NetDataContractSerializer.ReadObject(reader, false));
                        }
                    }
                }
                else
                {
                    return(_XsdDataContractSerializer.ReadObject(reader, false));
                }
                break;

            case BindableDynamicObject.XmlSettings.DataTypeSchema.Net:
                declaredType = reader.GetAttribute(NetTypeAttributeName, NsNet);
                if (string.IsNullOrEmpty(declaredType))
                {
                    if (xmlSettings.IsImplicit())
                    {
                        declaredType = reader.GetAttribute(XsdTypeAttributeName, XmlSchema.InstanceNamespace);
                    }
                    if (!string.IsNullOrEmpty(declaredType))
                    {
                        return(_XsdDataContractSerializer.ReadObject(reader, false));
                    }
                }
                else
                {
                    return(_NetDataContractSerializer.ReadObject(reader, false));
                }
                break;

            default:
                if (xmlSettings.IsImplicit())
                {
                    declaredType = reader.GetAttribute(XsdTypeAttributeName, XmlSchema.InstanceNamespace);
                    if (string.IsNullOrEmpty(declaredType))
                    {
                        declaredType = reader.GetAttribute(NetTypeAttributeName, NsNet);
                        if (!string.IsNullOrEmpty(declaredType))
                        {
                            return(_NetDataContractSerializer.ReadObject(reader, false));
                        }
                    }
                    else
                    {
                        return(_XsdDataContractSerializer.ReadObject(reader, false));
                    }
                }
                break;
            }

            return(reader.ReadElementContentAsString());
        }