blob: ce7891da50f53bc7ffefc05c2b14f2061ed3db1c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
namespace DotNetOpenAuth.AspNet.Clients {
using System;
using System.Collections.Generic;
using System.Xml.Linq;
internal static class DictionaryExtensions {
/// <summary>
/// Adds a key/value pair to the specified dictionary if the value is not null or empty.
/// </summary>
/// <param name="dictionary">The dictionary.</param>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
public static void AddItemIfNotEmpty(this IDictionary<string, string> dictionary, string key, string value) {
if (key == null) {
throw new ArgumentNullException("key");
}
if (!String.IsNullOrEmpty(value)) {
dictionary[key] = value;
}
}
/// <summary>
/// Adds the value from an XDocument with the specified element name if it's not empty.
/// </summary>
/// <param name="dictionary">The dictionary.</param>
/// <param name="document">The document.</param>
/// <param name="elementName">Name of the element.</param>
public static void AddDataIfNotEmpty(
this Dictionary<string, string> dictionary,
XDocument document,
string elementName) {
var element = document.Root.Element(elementName);
if (element != null) {
dictionary.AddItemIfNotEmpty(elementName, element.Value);
}
}
}
}
|