Example #1
0
 /// <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));
 }
Example #2
0
 /// <summary>
 /// Gets an <see cref="IEnumerable{String}"/> that will return all format parameters used within the format string.
 /// </summary>
 /// <param name="formatString">The format string to be parsed</param>
 /// <param name="openBraceChar">The character used to begin parameters</param>
 /// <param name="closeBraceChar">The character used to end parameters</param>
 /// <returns></returns>
 public static IEnumerable <string> GetFormatParameters(
     this string formatString,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     return(FormatWithMethods.GetFormatParameters(formatString, openBraceChar, closeBraceChar));
 }
Example #3
0
 /// <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));
 }
Example #4
0
 /// <summary>
 /// Produces a <see cref="FormattableString"/> representing the input format string.
 /// </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 resultant <see cref="FormattableString"/></returns>
 public static FormattableString FormattableWith(
     this string formatString,
     Func <string, ReplacementResult> handler,
     MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
     object fallbackReplacementValue         = null,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     return(FormatWithMethods.FormattableWith(
                formatString,
                handler,
                missingKeyBehaviour,
                fallbackReplacementValue,
                openBraceChar,
                closeBraceChar));
 }
Example #5
0
 /// <summary>
 /// Produces a <see cref="FormattableString"/> representing the input format string.
 /// </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 resultant <see cref="FormattableString"/></returns>
 public static FormattableString FormattableWith(
     this string formatString,
     IDictionary <string, object> replacements,
     MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
     object fallbackReplacementValue         = null,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     return(FormatWithMethods.FormattableWith(
                formatString,
                replacements,
                missingKeyBehaviour,
                fallbackReplacementValue,
                openBraceChar,
                closeBraceChar));
 }
Example #6
0
 /// <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));
 }
Example #7
0
 /// <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));
 }
Example #8
0
 /// <summary>
 /// Produces a <see cref="FormattableString"/> representing the input format string.
 /// </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 resultant <see cref="FormattableString"/></returns>
 public static FormattableString FormattableWith(
     this string formatString,
     Func <string, ReplacementResult> handler)
 {
     return(FormatWithMethods.FormattableWith(formatString, handler));
 }
Example #9
0
 /// <summary>
 /// Produces a <see cref="FormattableString"/> representing the input format string.
 /// </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 resultant <see cref="FormattableString"/></returns>
 public static FormattableString FormattableWith(this string formatString, IDictionary <string, object> replacements)
 {
     return(FormatWithMethods.FormattableWith(formatString, replacements));
 }