Exemplo n.º 1
0
        public void Copy(ItemType obj)
        {
            if (obj == null)
                return;

            // copy all of the properties
            foreach (PropertyInfo pi in this.GetType().GetProperties())
            {
                if (pi.Name == "Fields")
                    continue;
                var val = pi.GetValue(obj, null);
                pi.SetValue(this, val, null);
            }
        }
Exemplo n.º 2
0
 public ItemType(ItemType itemType)
 {
     Copy(itemType);
 }
Exemplo n.º 3
0
        private bool Update(ItemType requestedItemType, ItemType originalItemType, ItemType newItemType)
        {
            bool updated = false;
            // TODO: timestamps!
            Type t = requestedItemType.GetType();
            foreach (PropertyInfo pi in t.GetProperties())
            {
                object serverValue = pi.GetValue(requestedItemType, null);
                object origValue = pi.GetValue(originalItemType, null);
                object newValue = pi.GetValue(newItemType, null);

                // if the value has changed, process further
                if (!object.Equals(origValue, newValue))
                {
                    // if the server has the original value, make the update
                    if (object.Equals(serverValue, origValue))
                    {
                        pi.SetValue(requestedItemType, newValue, null);
                        updated = true;
                    }
                }
            }

            return updated;
        }