Beispiel #1
0
        public bool Equals(IKeyedItem p)
        {
            // If parameter is null return false:
            if (p == null)
            {
                return false;
            }

            // Return true if the fields match:
            return (Guid == p.Guid);
        }
 /// <summary>
 /// Compares two keyed types.
 /// </summary>
 /// <typeparam name="TKey">Type of the key.</typeparam>
 /// <param name="source">Source object.</param>
 /// <param name="other">Object to compare <paramref name="source"/> with.</param>
 /// <returns>True when objects are equal, false otherwise.</returns>
 public static bool AreKeyEqual <TKey>(this IKeyedItem <TKey> source, IKeyedItem other)
 {
     if (ReferenceEquals(source, other))
     {
         return(true);
     }
     if (ReferenceEquals(other, null) || ReferenceEquals(source, null) || source.GetType() != other.GetType())
     {
         return(false);
     }
     return(Equals(source.Key, ((IKeyedItem <TKey>)other).Key));
 }
        public void TryGetValue(
            int collectionSize,
            Named <KeyedCollectionGetKeyedValue <TKey, TValue> >
            generateKeyedItem)
        {
            TKey[] keys;
            IKeyedItem <TKey, TValue>[] items;
            IKeyedItem <TKey, TValue>[] itemsWithKeys;
            var collection =
                new TestKeyedCollectionOfIKeyedItem <TKey, TValue>();

            collection.AddItems(
                generateKeyedItem.Value.Bind(
                    GenerateValue,
                    GetKeyForItem),
                ki => ki.Key,
                collectionSize,
                out keys,
                out items,
                out itemsWithKeys);
            IKeyedItem <TKey, TValue> itemNotIn =
                generateKeyedItem.Value(GenerateValue, GetKeyForItem);

            TKey keyNotIn = itemNotIn.Key;

            if (keyNotIn == null)
            {
                IKeyedItem <TKey, TValue> item;
                Assert.Throws <ArgumentNullException>(
                    () => collection.TryGetValue(keyNotIn, out item));
            }
            else
            {
                IKeyedItem <TKey, TValue> item;
                Assert.False(collection.TryGetValue(keyNotIn, out item));
            }
            foreach (TKey k in keys)
            {
                IKeyedItem <TKey, TValue> item;
                TKey key = k;
                if (key == null)
                {
                    Assert.Throws <ArgumentNullException>(
                        () => collection.TryGetValue(key, out item));
                    continue;
                }
                Assert.True(collection.TryGetValue(key, out item));
                Assert.Equal(item.Key, key);
            }
        }
        void RefreshDatabaseVariableElem(Element elem)
        {
            string varname = GetDatabaseVariable(elem);

            if (string.IsNullOrWhiteSpace(varname))
            {
                return;
            }

            if (elem is Switch sw)
            {
                App.Database.TryGetVariable(varname, bool.TryParse, out bool b);
                sw.IsToggled = b;
            }
            else if (elem is DropDown dropdown)
            {
                if (dropdown.ItemsSource is IKeyedItemList itemlist)
                {
                    string     str  = App.Database.GetVariable(varname);
                    IKeyedItem item = itemlist.Lookup(str);
                    dropdown.SelectedItem = item;
                }
            }
        }
Beispiel #5
0
 public void MyChangeItemKey(
     IKeyedItem <TKey, TValue> item,
     TKey newKey)
 {
     ChangeItemKey(item, newKey);
 }
Beispiel #6
0
 protected override TKey GetKeyForItem(
     IKeyedItem <TKey, TValue> item)
 {
     return(item.Key);
 }