Exemple #1
0
 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)));
 }
Exemple #2
0
 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))));
 }
Exemple #3
0
 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));
 }
Exemple #4
0
 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));
 }
Exemple #5
0
 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));
     }
 }
Exemple #6
0
 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))))));
 }
Exemple #7
0
 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))));
 }