//-----------------------------------------------------------------------
//
// Copyright (c) Microsoft. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.AspNet.Clients {
using System;
using System.Collections.Generic;
using System.Xml.Linq;
///
/// The dictionary extensions.
///
internal static class DictionaryExtensions {
#region Public Methods and Operators
///
/// Adds the value from an XDocument with the specified element name if it's not empty.
///
///
/// The dictionary.
///
///
/// The document.
///
///
/// Name of the element.
///
public static void AddDataIfNotEmpty(
this Dictionary dictionary, XDocument document, string elementName) {
var element = document.Root.Element(elementName);
if (element != null) {
dictionary.AddItemIfNotEmpty(elementName, element.Value);
}
}
///
/// Adds a key/value pair to the specified dictionary if the value is not null or empty.
///
///
/// The dictionary.
///
///
/// The key.
///
///
/// The value.
///
public static void AddItemIfNotEmpty(this IDictionary dictionary, string key, string value) {
if (key == null) {
throw new ArgumentNullException("key");
}
if (!string.IsNullOrEmpty(value)) {
dictionary[key] = value;
}
}
#endregion
}
}