System.Xml.Serialization.ListMap.FindElement C# (CSharp) Method

FindElement() public method

public FindElement ( object ob, int index, object memberValue ) : System.Xml.Serialization.XmlTypeMapElementInfo
ob object
index int
memberValue object
return System.Xml.Serialization.XmlTypeMapElementInfo
		public XmlTypeMapElementInfo FindElement (object ob, int index, object memberValue)
		{
			if (_itemInfo.Count == 1) 
				return (XmlTypeMapElementInfo) _itemInfo[0];
			else if (_choiceMember != null && index != -1)
			{
				Array values = (Array) XmlTypeMapMember.GetValue (ob, _choiceMember);
				if (values == null || index >= values.Length)
					throw new InvalidOperationException ("Invalid or missing choice enum value in member '" + _choiceMember + "'.");
				object val = values.GetValue (index);
				foreach (XmlTypeMapElementInfo elem in _itemInfo)
					if (elem.ChoiceValue != null && elem.ChoiceValue.Equals (val))
						return elem;
			}
			else
			{
				if (memberValue == null) return null;
				Type type = memberValue.GetType();
				foreach (XmlTypeMapElementInfo elem in _itemInfo)
					if (elem.TypeData.Type == type) return elem;
			}
			return null;
		}	

Same methods

ListMap::FindElement ( string elementName, string ns ) : System.Xml.Serialization.XmlTypeMapElementInfo

Usage Example

Example #1
0
        private object ReadListElement(XmlTypeMapping typeMap, bool isNullable, object list, bool canCreateInstance)
        {
            Type    type    = typeMap.TypeData.Type;
            ListMap listMap = (ListMap)typeMap.ObjectMap;

            if (type.IsArray && base.ReadNull())
            {
                return(null);
            }
            if (list == null)
            {
                if (!canCreateInstance || !typeMap.TypeData.HasPublicConstructor)
                {
                    throw base.CreateReadOnlyCollectionException(typeMap.TypeFullName);
                }
                list = this.CreateList(type);
            }
            if (base.Reader.IsEmptyElement)
            {
                base.Reader.Skip();
                if (type.IsArray)
                {
                    list = base.ShrinkArray((Array)list, 0, type.GetElementType(), false);
                }
                return(list);
            }
            int length = 0;

            base.Reader.ReadStartElement();
            base.Reader.MoveToContent();
            while (base.Reader.NodeType != XmlNodeType.EndElement)
            {
                if (base.Reader.NodeType == XmlNodeType.Element)
                {
                    XmlTypeMapElementInfo xmlTypeMapElementInfo = listMap.FindElement(base.Reader.LocalName, base.Reader.NamespaceURI);
                    if (xmlTypeMapElementInfo != null)
                    {
                        this.AddListValue(typeMap.TypeData, ref list, length++, this.ReadObjectElement(xmlTypeMapElementInfo), false);
                    }
                    else
                    {
                        base.UnknownNode(null);
                    }
                }
                else
                {
                    base.UnknownNode(null);
                }
                base.Reader.MoveToContent();
            }
            base.ReadEndElement();
            if (type.IsArray)
            {
                list = base.ShrinkArray((Array)list, length, type.GetElementType(), false);
            }
            return(list);
        }
All Usage Examples Of System.Xml.Serialization.ListMap::FindElement