You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
753 B
28 lines
753 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace FLocal.Core {
|
|
|
|
class Switch<TResult> : List<KeyValuePair<Predicate, Func<TResult>>> {
|
|
|
|
public void Add(Predicate checker, Func<TResult> calculator) {
|
|
this.Add(new KeyValuePair<Predicate,Func<TResult>>(checker, calculator));
|
|
}
|
|
|
|
public void Add(bool checkResult, Func<TResult> calculator) {
|
|
this.Add(() => checkResult, calculator);
|
|
}
|
|
|
|
public TResult Value {
|
|
get {
|
|
return this.Single(kvp => kvp.Key(), () => {
|
|
throw new FLocalException("Not found");
|
|
}).Value();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|