An alternative to UBB.threads
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.
 
 
 
 
FLocal/Web.Core/Switch.cs

28 lines
750 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Web.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();
}
}
}
}