static EnsureManager() { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); _ensureMethods = assemblies.SelectMany(asm => asm.GetTypes()) .SelectMany(type => type.GetMethods()) .Where(method => IsEnsureMethod(method)) .ToConcurrentDictionary(method => method, method => method.ReturnType); _ensureMethodsPerType = new ConcurrentDictionary <Type, MethodInfo[]>(); _ensureLambdas = _ensureMethods.Keys .Select(method => { var argumentEnumerator = ArgumentEnumerators.ForFunc <EnsureContext>(method, (ctxt, type) => ctxt.EntityOfType(type)); return(method: method, lambda: method.CompileTo <Func <EnsureContext, object> >(argumentEnumerator)); }) .ToConcurrentDictionary(pair => pair.method, pair => pair.lambda); _conditionMethodByName = assemblies .SelectMany(asm => asm.GetTypes()) .SelectMany(type => type.GetMethods()) .Where(method => IsEnsureCondition(method)) .ToConcurrentDictionary(method => method.Name); _conditionLambdasByName = _conditionMethodByName.Values .Select(method => { var argumentEnumerator = ArgumentEnumerators.ForFunc <EnsureContext>(method, (ctxt, type) => ctxt.EntityOfType(type)); return(method: method, lambda: method.CompileTo <Func <EnsureContext, bool> >(argumentEnumerator)); }) .ToConcurrentDictionary(pair => pair.method.Name, pair => pair.lambda); _conditionsPerEnsurer = _ensureMethods.Keys .SelectMany(method => method.GetCustomAttributes <EnsureIfAttribute>().Select(attrib => (method, attrib))) .Select(pair => new ConditionEntry { Ensurer = pair.method, ExpectedValue = pair.attrib.Value, ConditionName = pair.attrib.MethodName, Lambda = _conditionLambdasByName[pair.attrib.MethodName] }) .ToLookup(entry => entry.Ensurer); _history = new List <EnsureSessionHistory>(); _historySubject = new BehaviorSubject <ImmutableList <EnsureSessionHistory> >(ImmutableList <EnsureSessionHistory> .Empty); IsHistoryEnabled = false; }
public static Func <T, TProp, T> CompileCopyConstructor <T, TProp>(this MethodBase mb, PropertyInfo prop) { return(_compileTo <Func <T, TProp, T> >(mb, argumentEnumerator: ArgumentEnumerators.ForCopyCtor(mb, prop))); }
public static DelegateType CompileTo <DelegateType>(this MethodBase mb, params Func <List <ParameterExpression>, Expression>[] argumentEvaluators) { return(_compileTo <DelegateType>(mb, argumentEnumerator: ArgumentEnumerators.ForDetails(argumentEvaluators))); }