protected virtual object ReadClassInstance(XmlTypeMapping typeMap, bool isNullable, bool checkType)
        {
            if (isNullable && ReadNull())
            {
                return(null);
            }

            if (checkType)
            {
                System.Xml.XmlQualifiedName t = GetXsiType();
                if (t != null)
                {
                    XmlTypeMapping realMap = typeMap.GetRealElementMap(t.Name, t.Namespace);
                    if (realMap == null)
                    {
                        if (typeMap.TypeData.Type == typeof(object))
                        {
                            return(ReadTypedPrimitive(t));
                        }
                        else
                        {
                            throw CreateUnknownTypeException((System.Xml.XmlQualifiedName)t);
                        }
                    }
                    if (realMap != typeMap)
                    {
                        return(ReadObject(realMap, false, false));
                    }
                }
                else if (typeMap.TypeData.Type == typeof(object))
                {
                    return(ReadTypedPrimitive(AnyType));
                }
            }

            object ob = CreateInstance(typeMap.TypeData.Type, true);

            Reader.MoveToElement();
            bool isEmpty = Reader.IsEmptyElement;

            ReadClassInstanceMembers(typeMap, ob);

            if (isEmpty)
            {
                Reader.Skip();
            }
            else
            {
                ReadEndElement();
            }

            return(ob);
        }
Example #2
0
        protected virtual object ReadClassInstance(XmlTypeMapping typeMap, bool isNullable, bool checkType)
        {
            if (isNullable && base.ReadNull())
            {
                return(null);
            }
            if (checkType)
            {
                XmlQualifiedName xsiType = base.GetXsiType();
                if (xsiType != null)
                {
                    XmlTypeMapping realElementMap = typeMap.GetRealElementMap(xsiType.Name, xsiType.Namespace);
                    if (realElementMap == null)
                    {
                        if (typeMap.TypeData.Type == typeof(object))
                        {
                            return(base.ReadTypedPrimitive(xsiType));
                        }
                        throw base.CreateUnknownTypeException(xsiType);
                    }
                    else if (realElementMap != typeMap)
                    {
                        return(this.ReadObject(realElementMap, false, false));
                    }
                }
                else if (typeMap.TypeData.Type == typeof(object))
                {
                    return(base.ReadTypedPrimitive(XmlSerializationReaderInterpreter.AnyType));
                }
            }
            object obj = Activator.CreateInstance(typeMap.TypeData.Type, true);

            base.Reader.MoveToElement();
            bool isEmptyElement = base.Reader.IsEmptyElement;

            this.ReadClassInstanceMembers(typeMap, obj);
            if (isEmptyElement)
            {
                base.Reader.Skip();
            }
            else
            {
                base.ReadEndElement();
            }
            return(obj);
        }
		protected virtual object ReadClassInstance (XmlTypeMapping typeMap, bool isNullable, bool checkType)
		{
			if (isNullable && ReadNull()) return null;

			if (checkType) 
			{
                System.Xml.XmlQualifiedName t = GetXsiType();
				if (t != null) 
				{
					XmlTypeMapping realMap = typeMap.GetRealElementMap (t.Name, t.Namespace);
					if (realMap == null) {
						if (typeMap.TypeData.Type == typeof(object))
							return ReadTypedPrimitive (t);
						else
							throw CreateUnknownTypeException((System.Xml.XmlQualifiedName)t);
					}
					if (realMap != typeMap)
						return ReadObject (realMap, false, false);
				}
				else if (typeMap.TypeData.Type == typeof(object))
					return ReadTypedPrimitive (AnyType);
            }

			object ob = Activator.CreateInstance (typeMap.TypeData.Type, true);

			Reader.MoveToElement();
			bool isEmpty = Reader.IsEmptyElement;
			ReadClassInstanceMembers (typeMap, ob);

			if (isEmpty) Reader.Skip();
			else ReadEndElement();

			return ob;
		}