Sakura.AspNetCore.Extensions/Sakura.AspNetCore.Mvc.PagedList/PagerItemContentGenerators.cs
/// <summary>
///     Generate a <see cref="IPagerItemContentGenerator" /> according to the specified configuration text.
/// </summary>
/// <param name="configurationText">The configuration text which described the type and arguments of the generator.</param>
/// <returns>
///     The <see cref="IPagerItemContentGenerator" /> object generated accoding to
///     <paramref name="configurationText" />.
/// </returns>
/// <exception cref="ArgumentNullException">The <paramref name="configurationText" /> is <c>null</c>.</exception>
/// <exception cref="ArgumentException">The <paramref name="configurationText" /> cannot be parsed into excepted format.</exception>
/// <exception cref="NotSupportedException">
///     The generator type specified in <paramref name="configurationText" /> is not
///     supported.
/// </exception>
Generate a  according to the specified configuration text.
Generate a according to the specified configuration text .
public static IPagerItemContentGenerator FromConfiguration(string configurationText)
		{
			if (configurationText == null)
				throw new ArgumentNullException(nameof(configurationText));
			var pattern = @"^(?<type>.*?)(:(?<exp>.*)?)$";
			var matchResult = Regex.Match(configurationText, pattern,
				RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase |
				RegexOptions.Singleline);
			if (!matchResult.Success)
				throw new ArgumentException("The configurationText cannot be parsed.", nameof(configurationText));
			var type = matchResult.Groups["type"].Value.Trim().ToLowerInvariant();
			var exp = matchResult.Groups["exp"].Value;
			switch (type)
			{
				case "text":
					return Text(exp);
				case "html":
					return Html(exp);
				case "textformat":
					return TextFormat(exp);
				case "htmlformat":
					return HtmlFormat(exp);
				case "default":
					return Default;
				default:
					throw new NotSupportedException(
						$"The generator type string '{type}' in the configuration text is not a valid option.");
			}
		}
public static IPagerItemContentGenerator FromConfiguration ( string configurationText ) { if ( configurationText == null ) throw new ArgumentNullException ( nameof ( configurationText ) ) ; var pattern = @"^(?<type>.*?)(:(?<exp>.*)?)$" ; var matchResult = Regex . Match ( configurationText , pattern , RegexOptions . Compiled | RegexOptions . CultureInvariant | RegexOptions . ExplicitCapture | RegexOptions . IgnoreCase | RegexOptions . Singleline ) ; if ( ! matchResult . Success ) throw new ArgumentException ( " " , nameof ( configurationText ) ) ; var type = matchResult . Groups [ " " ] . Value . Trim ( ) . ToLowerInvariant ( ) ; var exp = matchResult . Groups [ " " ] . Value ; switch ( type ) { case " " : return Text ( exp ) ; case " " : return Html ( exp ) ; case " " : return TextFormat ( exp ) ; case " " : return HtmlFormat ( exp ) ; case " " : return Default ; default : throw new NotSupportedException ( $" The generator type string ' { type } ' in the configuration text is not a valid option. " ) ; } }
Generate a  according to the specified configuration text.
Generate a according to the specified configuration text .
// Type text, normalize first
The  object generated accoding to
.
The object generated accoding to .
The  is null
The is null
The  cannot be parsed into excepted format.
The cannot be parsed into excepted format .
The generator type specified in  is not
supported.
The generator type specified in is not supported .
configurationText
string
The configuration text which described the type and arguments of the generator.
The configuration text which described the type and arguments of the generator .