Esempio n. 1
0
        public virtual bool IsUpdateNeeded(Category other)
        {
            Type myType    = this.GetType();
            Type otherType = other.GetType();

            if (myType != otherType)
            {
                throw new ArgumentException(string.Format("Can't compare a {0} with a {1}", myType.Name, otherType.Name));
            }

            FieldInfo[] fields = myType.GetFields();
            foreach (FieldInfo fi in fields)
            {
                object[] attribs  = fi.GetCustomAttributes(true);
                bool     ignoreMe = false;
                foreach (object o in attribs)
                {
                    if (o is JsonIgnoreAttribute)
                    {
                        ignoreMe = true;
                        break;
                    }
                }
                if (ignoreMe)
                {
                    continue;
                }

                object valA = fi.GetValue(this);
                object valB = fi.GetValue(other);
                if ((valA == null) && (valB.Equals("")))
                {
                    return(false);
                }
                if ((valB == null) && (valA.Equals("")))
                {
                    return(false);
                }
                if (!valA.Equals(valB))
                {
                    return(true);
                }
            }
            return(false);
        }