CSharp examples for System.Collections.Generic:IDictionary
Safely get the value of the given property, or return the default if no value is present in the dictionary
// Licensed under the Apache License, Version 2.0 (the "License"); using System.Linq; using System.Collections.Generic; using System;//from w w w. j a v a 2 s . c o m public class Main{ /// <summary> /// Safely get the value of the given property, or return the default if no value is present in the dictionary /// </summary> /// <typeparam name="TKey">The disctionary key type</typeparam> /// <typeparam name="TValue">The dictionary value type</typeparam> /// <param name="dictionary">The extensions dictionary to search</param> /// <param name="property">The property to serach for</param> /// <returns>The value stored in the dictionary, or the default if no value is specified</returns> public static TValue GetProperty<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey property) { if (dictionary.ContainsKey(property)) { return dictionary[property]; } return default(TValue); } }