Exemple #1
0
 public XmlTypeMapElementInfo FindElement(object ob, object memberValue)
 {
     if (this._elementInfo.Count == 1)
     {
         return((XmlTypeMapElementInfo)this._elementInfo[0]);
     }
     if (this._choiceMember != null)
     {
         object value = XmlTypeMapMember.GetValue(ob, this._choiceMember);
         foreach (object obj in this._elementInfo)
         {
             XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)obj;
             if (xmlTypeMapElementInfo.ChoiceValue != null && xmlTypeMapElementInfo.ChoiceValue.Equals(value))
             {
                 return(xmlTypeMapElementInfo);
             }
         }
     }
     else
     {
         if (memberValue == null)
         {
             return((XmlTypeMapElementInfo)this._elementInfo[0]);
         }
         foreach (object obj2 in this._elementInfo)
         {
             XmlTypeMapElementInfo xmlTypeMapElementInfo2 = (XmlTypeMapElementInfo)obj2;
             if (xmlTypeMapElementInfo2.TypeData.Type.IsInstanceOfType(memberValue))
             {
                 return(xmlTypeMapElementInfo2);
             }
         }
     }
     return(null);
 }
Exemple #2
0
 private object GetMemberValue(XmlTypeMapMember member, object ob, bool isValueList)
 {
     if (isValueList)
     {
         return(((object[])ob)[member.GlobalIndex]);
     }
     return(member.GetValue(ob));
 }
 object GetMemberValue(XmlTypeMapMember member, object ob, bool isValueList)
 {
     if (isValueList)
     {
         return(((object[])ob)[member.Index]);
     }
     else
     {
         return(member.GetValue(ob));
     }
 }
 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();
         XmlTypeMapElementInfo bestMatch = null;
         foreach (XmlTypeMapElementInfo elem in _itemInfo)
         {
             if (elem.TypeData.Type == type)
             {
                 return(elem);
             }
             if (elem.TypeData.Type.IsAssignableFrom(type) &&
                 (bestMatch == null || elem.TypeData.Type.IsAssignableFrom(bestMatch.TypeData.Type)))
             {
                 bestMatch = elem;
             }
         }
         return(bestMatch);
     }
     return(null);
 }
Exemple #5
0
 public XmlTypeMapElementInfo FindElement(object ob, int index, object memberValue)
 {
     if (this._itemInfo.Count == 1)
     {
         return((XmlTypeMapElementInfo)this._itemInfo[0]);
     }
     if (this._choiceMember != null && index != -1)
     {
         Array array = (Array)XmlTypeMapMember.GetValue(ob, this._choiceMember);
         if (array == null || index >= array.Length)
         {
             throw new InvalidOperationException("Invalid or missing choice enum value in member '" + this._choiceMember + "'.");
         }
         object value = array.GetValue(index);
         foreach (object obj in this._itemInfo)
         {
             XmlTypeMapElementInfo xmlTypeMapElementInfo = (XmlTypeMapElementInfo)obj;
             if (xmlTypeMapElementInfo.ChoiceValue != null && xmlTypeMapElementInfo.ChoiceValue.Equals(value))
             {
                 return(xmlTypeMapElementInfo);
             }
         }
     }
     else
     {
         if (memberValue == null)
         {
             return(null);
         }
         Type type = memberValue.GetType();
         foreach (object obj2 in this._itemInfo)
         {
             XmlTypeMapElementInfo xmlTypeMapElementInfo2 = (XmlTypeMapElementInfo)obj2;
             if (xmlTypeMapElementInfo2.TypeData.Type == type)
             {
                 return(xmlTypeMapElementInfo2);
             }
         }
     }
     return(null);
 }
		object GetMemberValue (XmlTypeMapMember member, object ob, bool isValueList)
		{
			if (isValueList) return ((object[])ob)[member.GlobalIndex];
			else return member.GetValue (ob);
		}