C# Класс NContrib.StringInjector

Originally from: http://mo.notono.us/2008/07/c-stringinject-format-strings-by-key.html Injects an object into a string using named replacements. Supports standard formatting.
Показать файл Открыть проект

Открытые методы

Метод Описание
Inject ( this formatString, Hashtable attributes ) : string

Replaces keys in a string with the values of matching hashtable entries using the CurrentCulture for formatting. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.

Inject ( this formatString, Hashtable attributes, IFormatProvider formatProvider ) : string

Replaces keys in a string with the values of matching hashtable entries using the specified format provider. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.

Inject ( this formatString, IDictionary dictionary ) : string

Replaces keys in a string with the values of matching dictionary entries using the CurrentCulture for formatting. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.

Inject ( this formatString, IDictionary dictionary, IFormatProvider formatProvider ) : string

Replaces keys in a string with the values of matching dictionary entries using the specified format provider Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.

Inject ( this formatString, object injectionObject ) : string

Replaces keys in a string with the values of matching object properties using the CurrentCulture for formatting. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.

Inject ( this formatString, object injectionObject, IFormatProvider formatProvider ) : string

Replaces keys in a string with the values of matching object properties using the specified format provider Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.

InjectSingleValue ( this formatString, string key, object replacementValue, IFormatProvider formatProvider ) : string

Replaces all instances of a 'key' (e.g. {foo} or {foo:SomeFormat}) in a string with an optionally formatted value, and returns the result.

Приватные методы

Метод Описание
GetPropertyHash ( object properties ) : Hashtable

Creates a HashTable based on current object state. Copied from the MVCToolkit HtmlExtensionUtility class

Описание методов

Inject() публичный статический Метод

Replaces keys in a string with the values of matching hashtable entries using the CurrentCulture for formatting. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.
public static Inject ( this formatString, Hashtable attributes ) : string
formatString this The format string, containing keys like {foo} and {foo:SomeFormat}.
attributes System.Collections.Hashtable A with keys and values to inject into the string
Результат string

Inject() публичный статический Метод

Replaces keys in a string with the values of matching hashtable entries using the specified format provider. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.
public static Inject ( this formatString, Hashtable attributes, IFormatProvider formatProvider ) : string
formatString this The format string, containing keys like {foo} and {foo:SomeFormat}.
attributes System.Collections.Hashtable A with keys and values to inject into the string
formatProvider IFormatProvider
Результат string

Inject() публичный статический Метод

Replaces keys in a string with the values of matching dictionary entries using the CurrentCulture for formatting. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.
public static Inject ( this formatString, IDictionary dictionary ) : string
formatString this The format string, containing keys like {foo} and {foo:SomeFormat}.
dictionary IDictionary An with keys and values to inject into the string
Результат string

Inject() публичный статический Метод

Replaces keys in a string with the values of matching dictionary entries using the specified format provider Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.
public static Inject ( this formatString, IDictionary dictionary, IFormatProvider formatProvider ) : string
formatString this The format string, containing keys like {foo} and {foo:SomeFormat}.
dictionary IDictionary An with keys and values to inject into the string
formatProvider IFormatProvider
Результат string

Inject() публичный статический Метод

Replaces keys in a string with the values of matching object properties using the CurrentCulture for formatting. Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.
public static Inject ( this formatString, object injectionObject ) : string
formatString this The format string, containing keys like {foo} and {foo:SomeFormat}.
injectionObject object The object whose properties should be injected in the string
Результат string

Inject() публичный статический Метод

Replaces keys in a string with the values of matching object properties using the specified format provider Uses String.Format(IFormatProvider, string, object[]) internally; custom formats should match those used for that method.
public static Inject ( this formatString, object injectionObject, IFormatProvider formatProvider ) : string
formatString this The format string, containing keys like {foo} and {foo:SomeFormat}.
injectionObject object The object whose properties should be injected in the string
formatProvider IFormatProvider Format provider used for default formatting
Результат string

InjectSingleValue() публичный статический Метод

Replaces all instances of a 'key' (e.g. {foo} or {foo:SomeFormat}) in a string with an optionally formatted value, and returns the result.
public static InjectSingleValue ( this formatString, string key, object replacementValue, IFormatProvider formatProvider ) : string
formatString this The string containing the key; unformatted ({foo}), or formatted ({foo:SomeFormat})
key string The key name (foo)
replacementValue object The replacement value; if null is replaced with an empty string
formatProvider IFormatProvider
Результат string