예제 #1
0
 /// <summary>
 /// Constructs a case based on a regular expression.
 /// </summary>
 /// <param name="regex"> The regex for condition.</param>
 /// <param name="selector"> The contextual selector for the case.</param>
 public RegexCase(Regex regex, ContextualSelector <string, R> selector)
 {
     SetField.CheckNull(nameof(selector), selector);
     this.Selector = selector;
     SetField.NotNull(out this.Regex, nameof(regex), regex);
     this.Condition = this.IsMatch;
 }
예제 #2
0
 /// <summary>
 /// Constructs a case.
 /// </summary>
 /// <param name="condition"> The condition of the case.</param>
 /// <param name="selector"> The contextual selector of the case.</param>
 public Case(Func <T, bool> condition, ContextualSelector <T, R> selector)
 {
     SetField.CheckNull(nameof(condition), condition);
     this.Condition = condition;
     SetField.CheckNull(nameof(selector), selector);
     this.Selector = selector;
 }
예제 #3
0
 /// <summary>
 /// Constructs the default case for switch.
 /// </summary>
 /// <param name="selector"> The contextual selector that will be called in default case.</param>
 public DefaultCase(ContextualSelector <T, R> selector)
     : base(obj => true, selector)
 {
 }
예제 #4
0
 /// <summary>
 /// Constructs a case to use as the default.
 /// </summary>
 /// <typeparam name="T"> The type of incoming value to case.</typeparam>
 /// <typeparam name="R"> The type of the object returned by selector.</typeparam>
 /// <param name="selector"> The contextual selector of the case.</param>
 /// <returns>The case.</returns>
 public static ICase <T, R> Default <T, R>(ContextualSelector <T, R> selector)
 {
     return(new DefaultCase <T, R>(selector));
 }
예제 #5
0
 /// <summary>
 /// Constructs a case based on a regular expression.
 /// </summary>
 /// <typeparam name="R"> The type of the object returned by selector.</typeparam>
 /// <param name="regex"> The regex for condition.</param>
 /// <param name="selector"> The contextual selector for the case.</param>
 /// <returns>The case.</returns>
 public static ICase <string, R> Case <R>(Regex regex, ContextualSelector <string, R> selector)
 {
     return(new RegexCase <R>(regex, selector));
 }
예제 #6
0
 /// <summary>
 /// Constructs a case.
 /// </summary>
 /// <typeparam name="T"> The type of incoming value to case.</typeparam>
 /// <typeparam name="R"> The type of the object returned by selector.</typeparam>
 /// <param name="condition"> The condition of the case.</param>
 /// <param name="selector"> The contextual selector of the case.</param>
 /// <returns></returns>
 public static ICase <T, R> Case <T, R>(Func <T, bool> condition, ContextualSelector <T, R> selector)
 {
     return(new Case <T, R>(condition, selector));
 }