Func <InvocationContext, object, bool> CompileSwitchCase(CompileContext ctx, SwitchCase switchCase) { int valueLength = switchCase.TestValues.Count; var valueEvals = new CompiledDelegate[valueLength]; for (int i = 0; i < valueLength; i++) { valueEvals[i] = switchCase.TestValues[i].Compile(ctx); } var bodyEval = switchCase.Body.Compile(ctx); return((invoke, value) => { bool isMatch = false; for (int i = 0; i < valueLength; i++) { if (object.Equals(value, valueEvals[i](invoke))) { isMatch = true; break; } } if (!isMatch) { return false; } bodyEval(invoke); return true; }); }
public override CompiledDelegate Compile(CompileContext ctx) { var valueEval = testValue.Compile(ctx); int caseLength = cases.Count; var caseEvals = new Func <InvocationContext, object, bool> [caseLength]; CompiledDelegate defaultBodyEval = null; for (int i = 0; i < caseLength; i++) { caseEvals[i] = CompileSwitchCase(ctx, cases[i]); } if (defaultBody != null) { defaultBodyEval = defaultBody.Compile(ctx); } return((invoke) => { var _caseLength = caseLength; var _caseEvals = caseEvals; var value = valueEval(invoke); for (int i = 0; i < _caseLength; i++) { if (_caseEvals[i](invoke, value)) { return null; } } defaultBodyEval?.Invoke(invoke); return null; }); }
private object GetMapMethod(TypePair key, Func <CompiledDelegate, object> propertyAccessor) { CompiledDelegate @delegate = null; DelegateCache.TryGetValue(key, out @delegate); var mapMethod = propertyAccessor(@delegate); return(mapMethod); }
public static object Or(InvocationContext invoke, CompiledDelegate oper1, CompiledDelegate oper2) { object ret = oper1(invoke); if (IsTrue(ret)) { return(ret); } return(oper2(invoke)); //return Is(oper1(invoke)) || Is(oper2(invoke)); }
public SingleMapper <TSrc, TDest> GetSingleMapper <TSrc, TDest>() { CompiledDelegate @delegate = null; var key = new TypePair(typeof(TSrc), typeof(TDest)); DelegateCache.TryGetValue(key, out @delegate); var mapMethod = @delegate?.SingleTyped as Func <TSrc, TDest, TDest>; if (mapMethod == null) { throw new HappyMapperException(ErrorMessages.MissingMapping(key.SourceType, key.DestinationType)); } var mapper = new SingleMapper <TSrc, TDest>(mapMethod); return(mapper); }
public void VisitDelegate(CompiledDelegate @delegate, TypeMap map, Assembly assembly, CodeFile file) { @delegate.CollectionUntyped = Tools.CreateDelegate( Tools.ToCollectionUntypedDelegateType(map), assembly, file); }
public void VisitDelegate(CompiledDelegate @delegate, TypeMap map, Assembly assembly) { Builder.VisitDelegate(@delegate, map, assembly, Result.Files[map.TypePair]); }
public void VisitDelegate(CompiledDelegate @delegate, TypeMap map, Assembly assembly, CodeFile file) { @delegate.SingleTyped = Tools.CreateDelegate(map.DelegateTypeSingleTyped, assembly, file); }