Class NameValueCollectionDecoratorExtensions
- Namespace
- Cuemon.Net.Collections.Specialized
- Assembly
- Cuemon.Net.dll
Extension methods for the NameValueCollection class hidden behind the IDecorator<T> interface.
public static class NameValueCollectionDecoratorExtensions
- Inheritance
-
NameValueCollectionDecoratorExtensions
Examples
The following example demonstrates how to use the ToString extension method to convert a NameValueCollection into a URI query string.
using System;
using System.Collections.Specialized;
using Cuemon;
using Cuemon.Net;
using Cuemon.Net.Collections.Specialized;
namespace MyApp.Examples;
public class NameValueCollectionDecoratorExtensionsExample
{
public static void Main()
{
var nvc = new NameValueCollection
{
["name"] = "John Doe",
["city"] = "Copenhagen",
["country"] = "Denmark"
};
// Convert to URL query string with ampersand separator and URL encoding.
string queryString = Decorator.Enclose(nvc).ToString(FieldValueSeparator.Ampersand, urlEncode: true);
Console.WriteLine(queryString);
// Output:
// ?name=John%20Doe&city=Copenhagen&country=Denmark
}
}
Methods
ToString(IDecorator<NameValueCollection>, FieldValueSeparator, bool)
Returns a string that represents the enclosed NameValueCollection of the decorator.
public static string ToString(this IDecorator<NameValueCollection> decorator, FieldValueSeparator separator, bool urlEncode)
Parameters
decoratorIDecorator<NameValueCollection>The IDecorator<T> to extend.
separatorFieldValueSeparatorThe separator used to form the key-value pairs.
urlEncodeboolSpecify
trueto encode the values of the enclosed NameValueCollection of thedecoratorinto a URL-encoded string; otherwise,false. Default isfalse.
Returns
- string
A string that represents the enclosed NameValueCollection of the
decorator.
Exceptions
- ArgumentNullException
decoratorcannot be null.
See Also
IDecorator<T>
Decorator<T>