Exemplo n.º 1
0
 public void CloneInto(CollectionItemIdentifiers target, IReadOnlyDictionary <object, object> referenceTypeClonedKeys)
 {
     target.keyToIdMap.Clear();
     target.deletedItems.Clear();
     foreach (var key in keyToIdMap)
     {
         object clonedKey;
         if (key.Key.GetType().IsValueType || referenceTypeClonedKeys == null)
         {
             target.Add(key.Key, key.Value);
         }
         else if (referenceTypeClonedKeys.TryGetValue(key.Key, out clonedKey))
         {
             target.Add(clonedKey, key.Value);
         }
         else
         {
             throw new KeyNotFoundException("Unable to find the non-value type key in the dictionary of cloned keys.");
         }
     }
     foreach (var deletedItem in DeletedItems)
     {
         target.MarkAsDeleted(deletedItem);
     }
 }
Exemplo n.º 2
0
        public static bool TryGetCollectionItemIds(object instance, out CollectionItemIdentifiers itemIds)
        {
            var shadow = ShadowObject.Get(instance);

            if (shadow == null)
            {
                itemIds = null;
                return(false);
            }

            object result;

            itemIds = shadow.TryGetValue(CollectionItemIdKey, out result) ? (CollectionItemIdentifiers)result : null;
            return(result != null);
        }
Exemplo n.º 3
0
        public static CollectionItemIdentifiers GetCollectionItemIds(object instance)
        {
            if (instance.GetType().IsValueType)
            {
                throw new ArgumentException(@"The given instance is a value type and cannot have a item ids attached to it.", nameof(instance));
            }

            var    shadow = ShadowObject.GetOrCreate(instance);
            object result;

            if (shadow.TryGetValue(CollectionItemIdKey, out result))
            {
                return((CollectionItemIdentifiers)result);
            }

            var itemIds = new CollectionItemIdentifiers();

            shadow.Add(CollectionItemIdKey, itemIds);
            return(itemIds);
        }