Search Results for

    Show / Hide Table of Contents

    Class BiDirectionalDictionary<TFirst, TSecond>

    This is a dictionary guaranteed to have only one of each value and key. It may be searched either by TFirst or by TSecond, giving a unique answer because it is 1 to 1.

    Inheritance
    System.Object
    BiDirectionalDictionary<TFirst, TSecond>
    Implements
    System.Collections.Generic.IDictionary<TFirst, TSecond>
    System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<TFirst, TSecond>>
    System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TFirst, TSecond>>
    System.Collections.IEnumerable
    Inherited Members
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: ImageVault.Core.Lib.Collections.Specialized
    Assembly: ImageVault.Core.dll
    Syntax
    public class BiDirectionalDictionary<TFirst, TSecond> : IDictionary<TFirst, TSecond>, ICollection<KeyValuePair<TFirst, TSecond>>, IEnumerable<KeyValuePair<TFirst, TSecond>>, IEnumerable
    Type Parameters
    Name Description
    TFirst

    The type of the "key"

    TSecond

    The type of the "value"

    Constructors

    BiDirectionalDictionary()

    Initializes a new instance of the BiDirectionalDictionary class.

    Declaration
    public BiDirectionalDictionary()

    BiDirectionalDictionary(IEnumerable<KeyValuePair<TFirst, TSecond>>)

    Initializes a new instance of the BiDirectionalDictionary<TFirst, TSecond> class.

    Declaration
    public BiDirectionalDictionary(IEnumerable<KeyValuePair<TFirst, TSecond>> dictionary)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<TFirst, TSecond>> dictionary

    Properties

    Count

    The number of pairs stored in the dictionary

    Declaration
    public int Count { get; }
    Property Value
    Type Description
    System.Int32

    IsReadOnly

    Gets the IsReadOnly of the BiDirectionalDictionary

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    System.Boolean

    Item[TFirst]

    Get/Sets the TSecond item identified by the given arguments of the BiDirectionalDictionary

    Declaration
    public TSecond this[TFirst key] { get; set; }
    Parameters
    Type Name Description
    TFirst key
    Property Value
    Type Description
    TSecond
    Exceptions
    Type Condition
    System.NotImplementedException

    Keys

    Gets the Keys of the BiDirectionalDictionary

    Declaration
    public ICollection<TFirst> Keys { get; }
    Property Value
    Type Description
    System.Collections.Generic.ICollection<TFirst>

    Values

    Gets the Values of the BiDirectionalDictionary

    Declaration
    public ICollection<TSecond> Values { get; }
    Property Value
    Type Description
    System.Collections.Generic.ICollection<TSecond>

    Methods

    Add(TFirst, TSecond)

    Tries to add the pair to the dictionary. Throws an exception if either element is already in the dictionary

    Declaration
    public void Add(TFirst first, TSecond second)
    Parameters
    Type Name Description
    TFirst first
    TSecond second
    Exceptions
    Type Condition
    System.ArgumentException

    If duplicate first or second.

    Add(KeyValuePair<TFirst, TSecond>)

    Declaration
    public void Add(KeyValuePair<TFirst, TSecond> item)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<TFirst, TSecond> item

    Clear()

    Removes all items from the dictionary.

    Declaration
    public void Clear()

    Contains(KeyValuePair<TFirst, TSecond>)

    Returns a value indicating whether the specified item is contained in the BiDirectionalDictionary<TFirst, TSecond>.

    Declaration
    public bool Contains(KeyValuePair<TFirst, TSecond> item)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<TFirst, TSecond> item

    The item to locate in the BiDirectionalDictionary<TFirst, TSecond>.

    Returns
    Type Description
    System.Boolean

    true if the KeyValuePair<TFirst,TSecond> parameter is a member of the BiDirectionalDictionary<TFirst, TSecond>; otherwise, false.

    ContainsFirst(TFirst)

    Returns a value indicating whether the specified TFirst is contained in the BiDirectionalDictionary<TFirst, TSecond>.

    Declaration
    public bool ContainsFirst(TFirst first)
    Parameters
    Type Name Description
    TFirst first

    The TFirst to locate in the BiDirectionalDictionary<TFirst, TSecond>.

    Returns
    Type Description
    System.Boolean

    true if the TFirst parameter is a member of the BiDirectionalDictionary<TFirst, TSecond>; otherwise, false.

    ContainsKey(TFirst)

    Returns a value indicating whether the specified TFirst is contained in the BiDirectionalDictionary<TFirst, TSecond>.

    Declaration
    public bool ContainsKey(TFirst key)
    Parameters
    Type Name Description
    TFirst key

    The TFirst to locate in the BiDirectionalDictionary<TFirst, TSecond>.

    Returns
    Type Description
    System.Boolean

    true if the TFirst parameter is a member of the BiDirectionalDictionary<TFirst, TSecond>; otherwise, false.

    ContainsSecond(TSecond)

    Returns a value indicating whether the specified TSecond is contained in the BiDirectionalDictionary<TFirst, TSecond>.

    Declaration
    public bool ContainsSecond(TSecond second)
    Parameters
    Type Name Description
    TSecond second

    The TSecond to locate in the BiDirectionalDictionary<TFirst, TSecond>.

    Returns
    Type Description
    System.Boolean

    true if the TSecond parameter is a member of the BiDirectionalDictionary<TFirst, TSecond>; otherwise, false.

    CopyTo(KeyValuePair<TFirst, TSecond>[], Int32)

    Declaration
    public void CopyTo(KeyValuePair<TFirst, TSecond>[] array, int arrayIndex)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<TFirst, TSecond>[] array
    System.Int32 arrayIndex
    Exceptions
    Type Condition
    System.NotImplementedException

    GetByFirst(TFirst)

    Find the TSecond corresponding to the TFirst first Throws an exception if first is not in the dictionary.

    Declaration
    public TSecond GetByFirst(TFirst first)
    Parameters
    Type Name Description
    TFirst first

    the key to search for

    Returns
    Type Description
    TSecond

    the value corresponding to first

    Exceptions
    Type Condition
    System.ArgumentException

    If first.

    GetBySecond(TSecond)

    Find the TFirst corresponing to the Second second. Throws an exception if second is not in the dictionary.

    Declaration
    public TFirst GetBySecond(TSecond second)
    Parameters
    Type Name Description
    TSecond second

    the key to search for

    Returns
    Type Description
    TFirst

    the value corresponding to second

    Exceptions
    Type Condition
    System.ArgumentException

    If second.

    GetEnumerator()

    Declaration
    public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<TFirst, TSecond>>

    Remove(TFirst)

    Declaration
    public bool Remove(TFirst key)
    Parameters
    Type Name Description
    TFirst key
    Returns
    Type Description
    System.Boolean

    Remove(KeyValuePair<TFirst, TSecond>)

    Declaration
    public bool Remove(KeyValuePair<TFirst, TSecond> item)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<TFirst, TSecond> item
    Returns
    Type Description
    System.Boolean

    RemoveByFirst(TFirst)

    Remove the record containing first. If first is not in the dictionary, throws an Exception.

    Declaration
    public bool RemoveByFirst(TFirst first)
    Parameters
    Type Name Description
    TFirst first

    the key of the record to delete

    Returns
    Type Description
    System.Boolean
    Exceptions
    Type Condition
    System.ArgumentException

    If first.

    RemoveBySecond(TSecond)

    Remove the record containing second. If second is not in the dictionary, throws an Exception.

    Declaration
    public bool RemoveBySecond(TSecond second)
    Parameters
    Type Name Description
    TSecond second

    the key of the record to delete

    Returns
    Type Description
    System.Boolean
    Exceptions
    Type Condition
    System.ArgumentException

    If second.

    TryAdd(TFirst, TSecond)

    Tries to add the pair to the dictionary. Returns false if either element is already in the dictionary

    Declaration
    public bool TryAdd(TFirst first, TSecond second)
    Parameters
    Type Name Description
    TFirst first
    TSecond second
    Returns
    Type Description
    System.Boolean

    true if successfully added, false if either element are already in the dictionary

    TryGetByFirst(TFirst, out TSecond)

    Find the TSecond corresponding to the TFirst first. Returns false if first is not in the dictionary.

    Declaration
    public bool TryGetByFirst(TFirst first, out TSecond second)
    Parameters
    Type Name Description
    TFirst first

    the key to search for

    TSecond second

    the corresponding value

    Returns
    Type Description
    System.Boolean

    true if first is in the dictionary, false otherwise

    TryGetBySecond(TSecond, out TFirst)

    Find the TFirst corresponding to the TSecond second. Returns false if second is not in the dictionary.

    Declaration
    public bool TryGetBySecond(TSecond second, out TFirst first)
    Parameters
    Type Name Description
    TSecond second

    the key to search for

    TFirst first

    the corresponding value

    Returns
    Type Description
    System.Boolean

    true if second is in the dictionary, false otherwise

    TryGetValue(TFirst, out TSecond)

    Declaration
    public bool TryGetValue(TFirst key, out TSecond value)
    Parameters
    Type Name Description
    TFirst key
    TSecond value
    Returns
    Type Description
    System.Boolean

    TryRemoveByFirst(TFirst)

    Remove the record containing first, if there is one.

    Declaration
    public bool TryRemoveByFirst(TFirst first)
    Parameters
    Type Name Description
    TFirst first
    Returns
    Type Description
    System.Boolean

    If first is not in the dictionary, returns false, otherwise true

    TryRemoveBySecond(TSecond)

    Remove the record containing second, if there is one.

    Declaration
    public bool TryRemoveBySecond(TSecond second)
    Parameters
    Type Name Description
    TSecond second
    Returns
    Type Description
    System.Boolean

    If second is not in the dictionary, returns false, otherwise true

    Explicit Interface Implementations

    IEnumerable.GetEnumerator()

    Declaration
    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    System.Collections.IEnumerator

    Implements

    System.Collections.Generic.IDictionary<TKey, TValue>
    System.Collections.Generic.ICollection<T>
    System.Collections.Generic.IEnumerable<T>
    System.Collections.IEnumerable
    In This Article
    Back to top (c) Meriworks 2002-2022