public static Maybe <object> SimpleEval(Expression lambdaContainer) { return(MaybeExtension.OrElse <object>( MaybeExtension.SelectMany( MaybeExtension.SelectMany( MaybeExtension.SelectMany( MaybeExtension.MaybeAs <MethodCallExpression>((object)lambdaContainer, true), (Func <MethodCallExpression, Maybe <ConstantExpression> >) (methodCallExpression => MaybeExtension.MaybeAs <ConstantExpression>((object)methodCallExpression.Object, false)), (methodCallExpression, @object) => { var local_0 = new { methodCallExpression = methodCallExpression, @object = @object }; return local_0; }), param0 => Evaluator.GetParameters(param0.methodCallExpression), (param0, parameters) => { var local_0 = new { par = param0, parameters = parameters }; return local_0; }), param0 => MaybeExtension.ToMaybe <object>(param0.par.methodCallExpression.Method.Invoke(param0.par.@object == null ? (object)null : [email protected], Enumerable.ToArray <object>(param0.parameters))), (param0, lambdaExpression) => lambdaExpression), (Func <Maybe <object> >)(() => Evaluator.Evaluate(lambdaContainer)))); }
public Expression <Func <TTo, bool> > Convert(Expression <Func <TFrom, bool> > predicate) { MaybeExtension.GetOrDefault <BinaryExpression>(MaybeExtension.MaybeAs <BinaryExpression>((object)predicate.Body, true), (BinaryExpression)null); MaybeExtension.GetOrDefault <UnaryExpression>(MaybeExtension.MaybeAs <UnaryExpression>((object)predicate.Body, true), (UnaryExpression)null); MaybeExtension.GetOrDefault <MethodCallExpression>(MaybeExtension.MaybeAs <MethodCallExpression>((object)predicate.Body, true), (MethodCallExpression)null); return((Expression <Func <TTo, bool> >)null); }
public PropertyInfo GetPropertyInfoFromType(Type nestedType) { return(MaybeExtension.GetOrDefault <PropertyInfo>(MaybeExtension.MaybeAs <PropertyInfo>((object)Enumerable.FirstOrDefault <PropertyInfo>((IEnumerable <PropertyInfo>)nestedType.GetProperties(), (Func <PropertyInfo, bool>)(c => !this.IsStandardType(c.PropertyType))), true), (PropertyInfo)null)); }
public Type GetMemberType(Expression expression) { return(MaybeExtension.GetOrDefault <Type>(MaybeExtension.Bind <MemberExpression, Type>(MaybeExtension.MaybeAs <MemberExpression>((object)expression, true), (Func <MemberExpression, Type>)(p => p.Type)), (Type)null) ?? MaybeExtension.GetOrDefault <Type>(MaybeExtension.Bind <UnaryExpression, Type>(MaybeExtension.MaybeAs <UnaryExpression>((object)expression, true), (Func <UnaryExpression, Type>)(t => t.Operand.Type)), (Type)null)); }
public string GetMemberName(Expression expression) { return(Enumerable.FirstOrDefault <string>((IEnumerable <string>) new List <string>() { MaybeExtension.GetOrDefault <string>(MaybeExtension.Bind <MemberExpression, string>(MaybeExtension.MaybeAs <MemberExpression>((object)expression, true), (Func <MemberExpression, string>)(p => p.Member.Name)), (string)null), MaybeExtension.GetOrDefault <string>(MaybeExtension.Bind <UnaryExpression, string>(MaybeExtension.MaybeAs <UnaryExpression>((object)expression, true), (Func <UnaryExpression, Maybe <string> >)(t => MaybeExtension.Bind <MemberExpression, string>(MaybeExtension.MaybeAs <MemberExpression>((object)t.Operand, true), (Func <MemberExpression, string>)(p => p.Member.Name)))), (string)null), MaybeExtension.GetOrDefault <string>(MaybeExtension.Bind <MethodCallExpression, string>(MaybeExtension.MaybeAs <MethodCallExpression>((object)expression, true), (Func <MethodCallExpression, Maybe <string> >)(p => MaybeExtension.Bind <MemberExpression, string>(MaybeExtension.MaybeAs <MemberExpression>((object)MaybeExtension.GetOrDefault <Expression>(MaybeExtension.Bind <LambdaExpression, Expression>(MaybeExtension.MaybeAs <LambdaExpression>((object)Enumerable.Last <Expression>((IEnumerable <Expression>)p.Arguments), true), (Func <LambdaExpression, Expression>)(c => c.Body)), (Expression)null), true), (Func <MemberExpression, string>)(c => c.Member.Name)))), (string)null) }, (Func <string, bool>)(c => c != null))); }
public Type GetPropertyType(Type nestedType, List <Type> exceptTypeList) { return(MaybeExtension.GetOrDefault <Type>(MaybeExtension.Bind <PropertyInfo, Type>(MaybeExtension.MaybeAs <PropertyInfo>((object)Enumerable.FirstOrDefault <PropertyInfo>((IEnumerable <PropertyInfo>)nestedType.GetProperties(), (Func <PropertyInfo, bool>)(c => !this.IsStandardType(c.PropertyType) && !exceptTypeList.Contains(c.PropertyType))), true), (Func <PropertyInfo, Type>)(c => c.PropertyType)), (Type)null)); }
protected override Expression VisitMethodCall(MethodCallExpression node) { if (node.Method.IsGenericMethod && InlineApplyVisitor.ApplyMethods.Contains(node.Method.GetGenericMethodDefinition())) { return(ExpressionExtensions.Apply(MaybeExtension.GetOrThrow <LambdaExpression, Exception>(MaybeExtension.Bind <object, LambdaExpression>(Evaluator.SimpleEval(node.Arguments[0]), (Func <object, Maybe <LambdaExpression> >)(x => MaybeExtension.MaybeAs <LambdaExpression>(x, true))), (Func <Exception>)(() => new Exception("Could not Simplify expression " + (object)node))), Enumerable.Skip <Expression>((IEnumerable <Expression>)node.Arguments, 1))); } else { return(base.VisitMethodCall(node)); } }
public IEnumerable <string> GetValuesByKeyAndPredicate(string key, Func <XElement, bool> preFunc) { return(Enumerable.SelectMany <XElement, string>(Enumerable.Where <XElement>(this.GetElemetsByKey(key), preFunc), (Func <XElement, IEnumerable <string> >)(c => Enumerable.Select <XAttribute, string>(c.Attributes(), (Func <XAttribute, string>)(x => MaybeExtension.GetOrDefault <string>(MaybeExtension.Bind <XAttribute, string>(MaybeExtension.MaybeAs <XAttribute>((object)x, true), (Func <XAttribute, string>)(z => z.Value)), (string)null)))))); }
public IEnumerable <string> GetValuesByKeyAndAttribute(string key, string attrName) { return(Enumerable.Select <XElement, string>(Enumerable.Where <XElement>(this.GetElemetsByKey(key), (Func <XElement, bool>)(c => c.HasAttributes)), (Func <XElement, string>)(c => MaybeExtension.GetOrDefault <string>(MaybeExtension.Bind <XAttribute, string>(MaybeExtension.MaybeAs <XAttribute>((object)c.Attribute((XName)attrName), true), (Func <XAttribute, string>)(x => x.Value)), (string)null)))); }
public static Maybe <object> Evaluate(Expression argument) { return(MaybeExtension.OrElse <object>(MaybeExtension.Bind <ConstantExpression, object>(MaybeExtension.MaybeAs <ConstantExpression>((object)argument, true), (Func <ConstantExpression, object>)(x => x.Value)), (Func <Maybe <object> >)(() => MaybeExtension.SelectMany(MaybeExtension.SelectMany(MaybeExtension.MaybeAs <MemberExpression>((object)argument, true), (Func <MemberExpression, Maybe <ConstantExpression> >)(memberExpression => MaybeExtension.MaybeAs <ConstantExpression>((object)memberExpression.Expression, false)), (memberExpression, @object) => { var local_0 = new { memberExpression = memberExpression, @object = @object }; return local_0; }), param0 => MaybeExtension.OrElse <object>(MaybeExtension.Bind <PropertyInfo, object>(MaybeExtension.MaybeAs <PropertyInfo>((object)param0.memberExpression.Member, true), (Func <PropertyInfo, object>)(x => x.GetValue([email protected], (object[])null))), (Func <Maybe <object> >)(() => MaybeExtension.Bind <FieldInfo, object>(MaybeExtension.MaybeAs <FieldInfo>((object)param0.memberExpression.Member, true), (Func <FieldInfo, object>)(x => x.GetValue([email protected]))))), (param0, computedValue) => computedValue)))); }
public List <LastLevelNodeExpressionTreeModel> VisitRights(Expression exp) { WebRockExpressionConverterVisitor converterVisitor = new WebRockExpressionConverterVisitor(); List <LastLevelNodeExpressionTreeModel> list = new List <LastLevelNodeExpressionTreeModel>(); converterVisitor.Visit(exp); for (int index = 0; index < converterVisitor.Rights.Count; ++index) { Expression expression1 = converterVisitor.Lefts.Count < index || converterVisitor.Lefts.Count == 0 ? (Expression)null : converterVisitor.Lefts[index]; Expression expression2 = converterVisitor.Rights[index]; ExpressionType expressionType = converterVisitor.LastLevelNodeTypes.Count < index || converterVisitor.LastLevelNodeTypes.Count == 0 ? ExpressionType.Throw : converterVisitor.LastLevelNodeTypes[index].ValueOfExpressionType; MethodInfo methodInfo = converterVisitor.LastLevelNodeTypes.Count < index || converterVisitor.LastLevelNodeTypes.Count == 0 ? (MethodInfo)null : converterVisitor.LastLevelNodeTypes[index].CurrentMethodInfo; list.Add(new LastLevelNodeExpressionTreeModel() { LeftExpression = expression1, RightExpression = expression2, ExpressionWithMethodModel = new ExpressionWithMethodModel() { ValueOfExpressionType = expressionType, CurrentMethodInfo = methodInfo } }); } UnaryExpression orDefault = MaybeExtension.GetOrDefault <UnaryExpression>(MaybeExtension.MaybeAs <UnaryExpression>((object)exp, true), (UnaryExpression)null); if (orDefault != null) { list.Add(new LastLevelNodeExpressionTreeModel() { LeftExpression = orDefault.Operand, RightExpression = (Expression)null, ExpressionWithMethodModel = new ExpressionWithMethodModel() { ValueOfExpressionType = orDefault.NodeType, CurrentMethodInfo = orDefault.Method } }); } return(list); }