Determine if the given property has a value in IDictionary - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IDictionary

Description

Determine if the given property has a value in IDictionary

Demo Code

// Licensed under the Apache License, Version 2.0 (the "License");
using System.Linq;
using System.Collections.Generic;
using System;//w  ww.  j  a  v a  2s . c  o m

public class Main{
        /// <summary>
        /// Determine if the given property has a value
        /// </summary>
        /// <typeparam name="TKey">The disctionary key type</typeparam>
        /// <param name="dictionary">The extensions dictionary to search</param>
        /// <param name="property">The property to serach for</param>
        /// <returns>True if the proeprty has a value, otherwise false</returns>
        public static bool IsPropertySet<TKey>(this IDictionary<TKey, string> dictionary, TKey property)
        {
            return dictionary.ContainsKey(property) && !string.IsNullOrEmpty(dictionary[property]);
        }
}

Related Tutorials