Enhanced C#
Loyc library documentation
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Member Functions | List of all members
Loyc.Collections.ITryGet< in K, out V > Interface Template Reference

Enables access to TryGet extension methods for retrieving items from a collection without risk of exceptions. Unlike IReadOnlyDictionary{K, V}, this interface supports variance (e.g. ITryGet{object, string} can be assigned to ITryGet{string, object}) and it does not throw when the key is null. More...


Source file:
Inheritance diagram for Loyc.Collections.ITryGet< in K, out V >:
Loyc.Collections.AListBase< K, T > Loyc.Collections.IDictionaryImpl< K, V > Loyc.Collections.IDictionarySource< K, V > Loyc.Collections.IListSource< out T > Loyc.Collections.INegListSource< out T > Loyc.Collections.MapOrMMap< K, V > Loyc.Collections.AListBase< K, T >.Enumerator Loyc.Collections.AListBase< K, T >.ObserverMgr Loyc.Collections.AListBase< T > Loyc.Collections.BDictionary< K, V > Loyc.Collections.BList< T > Loyc.Collections.Bijection< K1, K2 > Loyc.Collections.IDictionaryEx< K, V > Loyc.Collections.IDictionaryImpl< K, V > Loyc.Collections.AListBase< K, T > Loyc.Collections.AListBase< K, T > Loyc.Collections.AListReverseView< K, T > Loyc.Collections.BList< T > Loyc.Collections.IArray< T > Loyc.Collections.ICharSource Loyc.Collections.IListAndListSource< T > Loyc.Collections.Impl.InternalDList< T > Loyc.Collections.IRange< out T > Loyc.Collections.ISparseListSource< T > Loyc.Collections.ReadOnlyArraySlice< T > Loyc.Collections.ReadOnlyListAsListSource< T > Loyc.Collections.ROLSlice< T, TList > Loyc.Collections.INegArray< T > Loyc.Collections.NegListSlice< T > Loyc.Collections.NegListSource< T > Loyc.Collections.Map< K, V > Loyc.Collections.MMap< K, V >

Remarks

Enables access to TryGet extension methods for retrieving items from a collection without risk of exceptions. Unlike IReadOnlyDictionary{K, V}, this interface supports variance (e.g. ITryGet{object, string} can be assigned to ITryGet{string, object}) and it does not throw when the key is null.

Public Member Functions

TryGet (K key, out bool fail)
 Gets the item for the specified key or index, and does not throw an exception on failure. More...
 

Member Function Documentation

V Loyc.Collections.ITryGet< in K, out V >.TryGet ( key,
out bool  fail 
)

Gets the item for the specified key or index, and does not throw an exception on failure.

Parameters
keyA lookup key that might be associated with a value in this object. If K is an integer, this value could be an index into a list.
failTryGet sets this to true on failure or false on success.
Returns
The element at the specified index, or default(V) if the index is not valid.

This method must not throw if key == null, although it may use third-party methods that throw (e.g. Object.Equals()).

Ideally the return type would be Maybe{T}, but that design would not allow variance on the output type (out V). Instead, an extension method TryGetExt.TryGet{K, V}(ITryGet{K, V}, K) is provided that returns Maybe{V}.

Referenced by Loyc.Syntax.Les.Les2LanguageService.Parse(), and Loyc.Syntax.Les.Les3LanguageService.Parse().