Sakura.AspNetCore.Extensions/Sakura.AspNetCore.Mvc.PagedList/PagerItemLinkGenerators.cs
/// <summary>
///     Generate a <see cref="IPagerItemLinkGenerator" /> from a configuration string.
/// </summary>
/// <param name="configurationText">The configuration string.</param>
/// <returns>The converted <see cref="IPagerItemLinkGenerator" />.</returns>
Generate a  from a configuration string.
Generate a from a configuration string .
public static IPagerItemLinkGenerator FromConfiguration(string configurationText)
		{
			if (configurationText == null)
				throw new ArgumentNullException(nameof(configurationText));
			if (configurationText == null)
				throw new ArgumentNullException(nameof(configurationText));
			const string 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 "query":
					const string p2 = @"^(?<name>.*?)=(?<value>.*)$";
					var m2 = Regex.Match(
						exp,
						p2,
						RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase
						| RegexOptions.Singleline);
					if (!m2.Success)
						throw new NotSupportedException(
							$"The generator expression string '{exp}' in the configuration text cannot be condiser as a query expression.");
					return QueryNameAndValueFormat(m2.Groups["name"].Value, m2.Groups["value"].Value);
				case "queryname":
					return QueryName(exp);
				case "format":
					return Format(exp);
				case "fixed":
					return Fixed(exp);
				case "default":
					return Default;
				case "disabled":
					return Disabled;
				default:
					throw new NotSupportedException(
						$"The generator type string '{type}' in the configuration text is not a valid option.");
			}
		}
public static IPagerItemLinkGenerator FromConfiguration ( string configurationText ) { if ( configurationText == null ) throw new ArgumentNullException ( nameof ( configurationText ) ) ; if ( configurationText == null ) throw new ArgumentNullException ( nameof ( configurationText ) ) ; const string 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 " " : const string p2 = @"^(?<name>.*?)=(?<value>.*)$" ; var m2 = Regex . Match ( exp , p2 , RegexOptions . Compiled | RegexOptions . CultureInvariant | RegexOptions . ExplicitCapture | RegexOptions . IgnoreCase | RegexOptions . Singleline ) ; if ( ! m2 . Success ) throw new NotSupportedException ( $" The generator expression string ' { exp } ' in the configuration text cannot be condiser as a query expression. " ) ; return QueryNameAndValueFormat ( m2 . Groups [ " " ] . Value , m2 . Groups [ " " ] . Value ) ; case " " : return QueryName ( exp ) ; case " " : return Format ( exp ) ; case " " : return Fixed ( exp ) ; case " " : return Default ; case " " : return Disabled ; default : throw new NotSupportedException ( $" The generator type string ' { type } ' in the configuration text is not a valid option. " ) ; } }
Generate a  from a configuration string.
Generate a from a configuration string .
// Type text, normalize first
The converted .
The converted .
configurationText
string
The configuration string.
The configuration string .