Exemple #1
0
        public static MemberInfox GetPropertyInfox(object obj, string PropertyPath, bool SearchForPriviteFieldInCasePublicFieldIsReadOnly = true)
        {
            MemberInfox info = null;

            foreach (var partName in (PropertyPath + "").Split('.'))//For nested properties like a.Name
            {
                info = new MemberInfox(obj, partName, SearchForPriviteFieldInCasePublicFieldIsReadOnly);
                if (!info.MemberExists)
                {
                    return(info);
                }
                obj = info.GetValue();
            }
            return(info);
        }
Exemple #2
0
 public void DeserializeNode(XmlNode node, object Instance, bool ThrowOnError = false)
 {
     mapXPathNodeToObject[Utility.GetXPath(node)] = Instance;
     foreach (XmlNode propertyNode in node.SelectNodes("Property"))
     {
         try
         {
             MemberInfox propertyInfo  = GetPropertyInfo(propertyNode, Instance);
             object      PropertyValue = propertyInfo.GetValue();
             var         childs        = GetChild(propertyNode);
             object      refObj        = CheckIfReferenceNode(propertyNode);
             if (refObj != null)
             {
                 propertyInfo.SetValue(refObj);
             }
             else if (Utility.IsSimpleType(propertyInfo.ValueType))//Simple property
             {
                 SetPropertyValue(Instance, propertyNode);
             }
             else if (childs.Count > 0 && childs[0].Name == "Array")//Array found
             {
                 propertyInfo.SetValue(DeserializeIEnumerable(childs[0], propertyInfo.ValueType, null, ThrowOnError));
             }
             else//Complex types
             {
                 if (PropertyValue == null)
                 {
                     if (!Utility.TryCreateInstance(propertyInfo.ValueType, out PropertyValue))
                     {
                         continue;
                     }
                     propertyInfo.SetValue(PropertyValue);
                 }
                 DeserializeNode(propertyNode, PropertyValue, ThrowOnError);
             }
         }
         catch { if (ThrowOnError)
                 {
                     throw;
                 }
         }
     }
 }
Exemple #3
0
 private bool IsEqualDefaut(MemberInfox property)
 {
     try
     {
         if (!Utility.IsSimpleType(property.ValueType))
         {
             return(false);
         }
         var    val = property.GetValue();
         object att = property.GetCustomAttributes(typeof(DefaultValueAttribute));
         if (att != null)
         {
             return(object.Equals(val, (att as DefaultValueAttribute).Value));
         }
         return(object.Equals(val, Utility.GetDefault(property.MemberType)));
     }
     catch {  }
     return(true);
 }