Esempio n. 1
0
 /// <summary>
 /// Gets an <see cref="IEnumerable{String}">IEnumerable&lt;string&gt;</see> 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(
     string formatString,
     char openBraceChar  = '{',
     char closeBraceChar = '}')
 {
     return(FormatHelpers.Tokenize(formatString, openBraceChar, closeBraceChar)
            .Where(t => t.TokenType == TokenType.Parameter)
            .Select(pt => pt.Value));
 }
Esempio n. 2
0
        public static FormattableString FormattableWith(
            string formatString,
            Func <string, ReplacementResult> handler,
            MissingKeyBehaviour missingKeyBehaviour = MissingKeyBehaviour.ThrowException,
            object fallbackReplacementValue         = null,
            char openBraceChar  = '{',
            char closeBraceChar = '}')
        {
            // get the parameters from the format string
            IEnumerable <FormatToken> tokens = FormatHelpers.Tokenize(formatString, openBraceChar, closeBraceChar);

            return(FormatHelpers.ProcessTokensIntoFormattableString(tokens, handler, missingKeyBehaviour, fallbackReplacementValue, formatString.Length * 2));
        }