Table of Contents

Class DictionaryDecoratorExtensions

Namespace
Cuemon.Collections.Specialized
Assembly
Cuemon.Core.dll

Extension methods for the IDictionary<TKey, TValue> interface hidden behind the IDecorator<T> interface.

public static class DictionaryDecoratorExtensions
Inheritance
DictionaryDecoratorExtensions

Examples

The following example demonstrates how to use the ToNameValueCollection extension method to convert an IDictionary<string, string[]> into a NameValueCollection.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using Cuemon;
using Cuemon.Collections.Specialized;

namespace MyApp.Examples;

public class DictionaryDecoratorExtensionsExample
{
    public static void Main()
    {
        var input = new Dictionary<string, string[]>
        {
            ["colors"] = new[] { "red", "green", "blue" },
            ["sizes"] = new[] { "small", "medium", "large" }
        };

        // Wrap the dictionary with Decorator and call the extension method.
        NameValueCollection nvc = Decorator.Enclose(input).ToNameValueCollection();

        foreach (string key in nvc)
        {
            Console.WriteLine("{0} = {1}", key, nvc[key]);

        // Output:
        // colors = red,green,blue
        // sizes = small,medium,large

}}
}

Methods

ToNameValueCollection(IDecorator<IDictionary<string, string[]>>, Action<DelimitedStringOptions<string>>)

Creates a NameValueCollection from the enclosed IDictionary{string,string[]} of the decorator.

public static NameValueCollection ToNameValueCollection(this IDecorator<IDictionary<string, string[]>> decorator, Action<DelimitedStringOptions<string>> setup = null)

Parameters

decorator IDecorator<IDictionary<string, string[]>>

The IDecorator<T> to extend.

setup Action<DelimitedStringOptions<string>>

The DelimitedStringOptions{string} which may be configured.

Returns

NameValueCollection

A NameValueCollection that is equivalent to the enclosed IDictionary{string,string[]} of the decorator.

Exceptions

ArgumentNullException

decorator cannot be null.

See Also