コード例 #1
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string with the values given by the properties on an input object.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="replacementObject">The object whose properties should be injected in the string</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     object replacementObject)
 {
     // wrap the type object in a wrapper Dictionary class that exposes the properties as dictionary keys via reflection
     return(FormatWithMethods.FormatWith(formatString, replacementObject));
 }
コード例 #2
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string with the values of the dictionary.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="replacements">An <see cref="IDictionary"/> with keys and values to inject into the string</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     IDictionary <string, string> replacements)
 {
     // wrap the IDictionary<string, string> in a wrapper Dictionary class that casts the values to objects as needed
     return(FormatWithMethods.FormatWith(formatString, replacements));
 }
コード例 #3
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string, using a handler function to provide the value
 /// of each parameter.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="handler">A handler function that transforms each parameter into a <see cref="ReplacementResult"/></param>
 /// <param name="missingKeyBehaviour">The behaviour to use when the format string contains a parameter that cannot be replaced by the handler</param>
 /// <param name="fallbackReplacementValue">When the <see cref="MissingKeyBehaviour.ReplaceWithFallback"/> is specified, this object is used as a fallback replacement value.</param>
 /// <param name="openBraceChar">The character used to begin parameters</param>
 /// <param name="closeBraceChar">The character used to end parameters</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     Func <string, ReplacementResult> handler,
     MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
     object fallbackReplacementValue         = null,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     return(FormatWithMethods.FormatWith(
                formatString,
                handler,
                missingKeyBehaviour,
                fallbackReplacementValue,
                openBraceChar,
                closeBraceChar));
 }
コード例 #4
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string with the values of the dictionary.
 /// The string representation of each object value in the dictionary is used as the format parameter.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="replacements">An <see cref="IDictionary"/> with keys and values to inject into the string</param>
 /// <param name="missingKeyBehaviour">The behaviour to use when the format string contains a parameter that is not present in the lookup dictionary</param>
 /// <param name="fallbackReplacementValue">When the <see cref="MissingKeyBehaviour.ReplaceWithFallback"/> is specified, this string is used as a fallback replacement value when the parameter is present in the lookup dictionary.</param>
 /// <param name="openBraceChar">The character used to begin parameters</param>
 /// <param name="closeBraceChar">The character used to end parameters</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     IDictionary <string, object> replacements,
     MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
     object fallbackReplacementValue         = null,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     return(FormatWithMethods.FormatWith(
                formatString,
                replacements,
                missingKeyBehaviour,
                fallbackReplacementValue,
                openBraceChar,
                closeBraceChar));
 }
コード例 #5
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string with the values of the dictionary.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="replacements">An <see cref="IDictionary"/> with keys and values to inject into the string</param>
 /// <param name="missingKeyBehaviour">The behaviour to use when the format string contains a parameter that is not present in the lookup dictionary</param>
 /// <param name="fallbackReplacementValue">When the <see cref="MissingKeyBehaviour.ReplaceWithFallback"/> is specified, this string is used as a fallback replacement value when the parameter is present in the lookup dictionary.</param>
 /// <param name="openBraceChar">The character used to begin parameters</param>
 /// <param name="closeBraceChar">The character used to end parameters</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     IDictionary <string, string> replacements,
     MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
     string fallbackReplacementValue         = null,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     // wrap the IDictionary<string, string> in a wrapper Dictionary class that casts the values to objects as needed
     return(FormatWithMethods.FormatWith(
                formatString,
                replacements,
                missingKeyBehaviour,
                fallbackReplacementValue,
                openBraceChar,
                closeBraceChar));
 }
コード例 #6
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string with the values given by the properties on an input object.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="replacementObject">The object whose properties should be injected in the string</param>
 /// <param name="missingKeyBehaviour">The behaviour to use when the format string contains a parameter that is not present in the lookup dictionary</param>
 /// <param name="fallbackReplacementValue">When the <see cref="MissingKeyBehaviour.ReplaceWithFallback"/> is specified, this string is used as a fallback replacement value when the parameter is present in the lookup dictionary.</param>
 /// <param name="openBraceChar">The character used to begin parameters</param>
 /// <param name="closeBraceChar">The character used to end parameters</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     object replacementObject,
     MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
     object fallbackReplacementValue         = null,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     // wrap the type object in a wrapper Dictionary class that exposes the properties as dictionary keys via reflection
     return(FormatWithMethods.FormatWith(
                formatString,
                replacementObject,
                missingKeyBehaviour,
                fallbackReplacementValue,
                openBraceChar,
                closeBraceChar));
 }
コード例 #7
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string, using a handler function to provide the value
 /// of each parameter.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="handler">A handler function that transforms each parameter into a <see cref="ReplacementResult"/></param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(
     this string formatString,
     Func <string, ReplacementResult> handler)
 {
     return(FormatWithMethods.FormatWith(formatString, handler));
 }
コード例 #8
0
ファイル: StringExtensions.cs プロジェクト: vuchl/FormatWith
 /// <summary>
 /// Formats a string with the values of the dictionary.
 /// The string representation of each object value in the dictionary is used as the format parameter.
 /// </summary>
 /// <param name="formatString">The format string, containing keys like {foo}</param>
 /// <param name="replacements">An <see cref="IDictionary"/> with keys and values to inject into the string</param>
 /// <returns>The formatted string</returns>
 public static string FormatWith(this string formatString, IDictionary <string, object> replacements)
 {
     return(FormatWithMethods.FormatWith(formatString, replacements));
 }