Exemplo n.º 1
0
        internal static IEnumerable <PropertyInfo> GetAllProperties(Type type, BindingFlags flags)
        {
            var  dictionary = new Dictionary <MetaPosition, PropertyInfo>();
            Type baseType   = type;

            do
            {
                foreach (var info in baseType.GetProperties(flags))
                {
                    if ((type == baseType) || IsPrivate(info))
                    {
                        var position = new MetaPosition(info);
                        dictionary[position] = info;
                    }
                }
                baseType = baseType.BaseType;
            } while (baseType != null);
            return(dictionary.Values);
        }
Exemplo n.º 2
0
        internal static IEnumerable <FieldInfo> GetAllFields(Type type, BindingFlags flags)
        {
            var  dictionary = new Dictionary <MetaPosition, FieldInfo>();
            Type baseType   = type;

            do
            {
                foreach (FieldInfo info in baseType.GetFields(flags))
                {
                    if (info.IsPrivate || (type == baseType))
                    {
                        var position = new MetaPosition(info);
                        dictionary[position] = info;
                    }
                }
                baseType = baseType.BaseType;
            } while (baseType != null);
            return(dictionary.Values);
        }
Exemplo n.º 3
0
            public override Expression VisitMemberAccess(MemberExpression m)
            {
                if (MetaPosition.AreSameMember(m.Member, this.association.ThisMember.Member))
                {
                    Expression[] keyValues = GetKeyValues(this.Visit(m.Expression), this.association.ThisKey);
                    return(Translator.WhereClauseFromSourceAndKeys(this.otherSouce, this.association.OtherKey.ToArray <MetaDataMember>(), keyValues));
                }
                Expression expression = this.Visit(m.Expression);

                if (expression == m.Expression)
                {
                    return(m);
                }
                if (((expression.Type != m.Expression.Type) && (m.Member.Name == "Count")) && TypeSystem.IsSequenceType(expression.Type))
                {
                    return(Expression.Call(typeof(Enumerable), "Count", new Type[] { TypeSystem.GetElementType(expression.Type) }, new Expression[] { expression }));
                }
                return(Expression.MakeMemberAccess(expression, m.Member));
            }
Exemplo n.º 4
0
            // Methods
            internal static bool AreSimilar(SqlExpression node1, SqlExpression node2)
            {
                if (node1 == node2)
                {
                    return(true);
                }
                if ((node1 != null) && (node2 != null))
                {
                    if (((node1.NodeType != node2.NodeType) || (node1.ClrType != node2.ClrType)) ||
                        (node1.SqlType != node2.SqlType))
                    {
                        return(false);
                    }
                    switch (node1.NodeType)
                    {
                    case SqlNodeType.ClientArray:
                    {
                        var array  = (SqlClientArray)node1;
                        var array2 = (SqlClientArray)node2;
                        if (array.Expressions.Count == array2.Expressions.Count)
                        {
                            int num7  = 0;
                            int count = array.Expressions.Count;
                            while (num7 < count)
                            {
                                if (!AreSimilar(array.Expressions[num7], array2.Expressions[num7]))
                                {
                                    return(false);
                                }
                                num7++;
                            }
                            return(true);
                        }
                        return(false);
                    }

                    case SqlNodeType.ClientCase:
                    {
                        var @case = (SqlClientCase)node1;
                        var case2 = (SqlClientCase)node2;
                        if (@case.Whens.Count == case2.Whens.Count)
                        {
                            int num9  = 0;
                            int num10 = @case.Whens.Count;
                            while (num9 < num10)
                            {
                                if (!AreSimilar(@case.Whens[num9].Match, case2.Whens[num9].Match) ||
                                    !AreSimilar(@case.Whens[num9].Value, case2.Whens[num9].Value))
                                {
                                    return(false);
                                }
                                num9++;
                            }
                            return(true);
                        }
                        return(false);
                    }

                    case SqlNodeType.ClientQuery:
                    {
                        var query  = (SqlClientQuery)node1;
                        var query2 = (SqlClientQuery)node2;
                        if (query.Arguments.Count == query2.Arguments.Count)
                        {
                            int num15 = 0;
                            int num16 = query.Arguments.Count;
                            while (num15 < num16)
                            {
                                if (!AreSimilar(query.Arguments[num15], query2.Arguments[num15]))
                                {
                                    return(false);
                                }
                                num15++;
                            }
                            return(true);
                        }
                        return(false);
                    }

                    case SqlNodeType.ColumnRef:
                    {
                        var ref2 = (SqlColumnRef)node1;
                        var ref3 = (SqlColumnRef)node2;
                        return(ref2.Column.Ordinal == ref3.Column.Ordinal);
                    }

                    case SqlNodeType.DiscriminatedType:
                    {
                        var type  = (SqlDiscriminatedType)node1;
                        var type2 = (SqlDiscriminatedType)node2;
                        return(AreSimilar(type.Discriminator, type2.Discriminator));
                    }

                    case SqlNodeType.Lift:
                        return(AreSimilar(((SqlLift)node1).Expression, ((SqlLift)node2).Expression));

                    case SqlNodeType.Link:
                    {
                        var link  = (SqlLink)node1;
                        var link2 = (SqlLink)node2;
                        if (MetaPosition.AreSameMember(link.Member.Member, link2.Member.Member))
                        {
                            if (link.KeyExpressions.Count != link2.KeyExpressions.Count)
                            {
                                return(false);
                            }
                            int num5 = 0;
                            int num6 = link.KeyExpressions.Count;
                            while (num5 < num6)
                            {
                                if (!AreSimilar(link.KeyExpressions[num5], link2.KeyExpressions[num5]))
                                {
                                    return(false);
                                }
                                num5++;
                            }
                            return(true);
                        }
                        return(false);
                    }

                    case SqlNodeType.Grouping:
                    {
                        var grouping  = (SqlGrouping)node1;
                        var grouping2 = (SqlGrouping)node2;
                        return(AreSimilar(grouping.Key, grouping2.Key) &&
                               AreSimilar(grouping.Group, grouping2.Group));
                    }

                    case SqlNodeType.JoinedCollection:
                    {
                        var joineds  = (SqlJoinedCollection)node1;
                        var joineds2 = (SqlJoinedCollection)node2;
                        if (!AreSimilar(joineds.Count, joineds2.Count))
                        {
                            return(false);
                        }
                        return(AreSimilar(joineds.Expression, joineds2.Expression));
                    }

                    case SqlNodeType.MethodCall:
                    {
                        var call  = (SqlMethodCall)node1;
                        var call2 = (SqlMethodCall)node2;
                        if ((call.Method == call2.Method) && AreSimilar(call.Object, call2.Object))
                        {
                            if (call.Arguments.Count != call2.Arguments.Count)
                            {
                                return(false);
                            }
                            int num17 = 0;
                            int num18 = call.Arguments.Count;
                            while (num17 < num18)
                            {
                                if (!AreSimilar(call.Arguments[num17], call2.Arguments[num17]))
                                {
                                    return(false);
                                }
                                num17++;
                            }
                            return(true);
                        }
                        return(false);
                    }

                    case SqlNodeType.Member:
                    {
                        var member  = (SqlMember)node1;
                        var member2 = (SqlMember)node2;
                        if (member.Member != member2.Member)
                        {
                            return(false);
                        }
                        return(AreSimilar(member.Expression, member2.Expression));
                    }

                    case SqlNodeType.OptionalValue:
                    {
                        var value2 = (SqlOptionalValue)node1;
                        var value3 = (SqlOptionalValue)node2;
                        return(AreSimilar(value2.Value, value3.Value));
                    }

                    case SqlNodeType.OuterJoinedValue:
                    case SqlNodeType.ValueOf:
                        return(AreSimilar(((SqlUnary)node1).Operand, ((SqlUnary)node2).Operand));

                    case SqlNodeType.SearchedCase:
                    {
                        var case3 = (SqlSearchedCase)node1;
                        var case4 = (SqlSearchedCase)node2;
                        if (case3.Whens.Count != case4.Whens.Count)
                        {
                            return(false);
                        }
                        int num11 = 0;
                        int num12 = case3.Whens.Count;
                        while (num11 < num12)
                        {
                            if (!AreSimilar(case3.Whens[num11].Match, case4.Whens[num11].Match) ||
                                !AreSimilar(case3.Whens[num11].Value, case4.Whens[num11].Value))
                            {
                                return(false);
                            }
                            num11++;
                        }
                        return(AreSimilar(case3.Else, case4.Else));
                    }

                    case SqlNodeType.New:
                    {
                        var new2 = (SqlNew)node1;
                        var new3 = (SqlNew)node2;
                        if ((new2.Args.Count != new3.Args.Count) || (new2.Members.Count != new3.Members.Count))
                        {
                            return(false);
                        }
                        int num  = 0;
                        int num2 = new2.Args.Count;
                        while (num < num2)
                        {
                            if (!AreSimilar(new2.Args[num], new3.Args[num]))
                            {
                                return(false);
                            }
                            num++;
                        }
                        int num3 = 0;
                        int num4 = new2.Members.Count;
                        while (num3 < num4)
                        {
                            if (
                                !MetaPosition.AreSameMember(new2.Members[num3].Member, new3.Members[num3].Member) ||
                                !AreSimilar(new2.Members[num3].Expression, new3.Members[num3].Expression))
                            {
                                return(false);
                            }
                            num3++;
                        }
                        return(true);
                    }

                    case SqlNodeType.Value:
                        return(Equals(((SqlValue)node1).Value, ((SqlValue)node2).Value));

                    case SqlNodeType.UserColumn:
                        return(((SqlUserColumn)node1).Name == ((SqlUserColumn)node2).Name);

                    case SqlNodeType.TypeCase:
                    {
                        var case5 = (SqlTypeCase)node1;
                        var case6 = (SqlTypeCase)node2;
                        if (!AreSimilar(case5.Discriminator, case6.Discriminator))
                        {
                            return(false);
                        }
                        if (case5.Whens.Count != case6.Whens.Count)
                        {
                            return(false);
                        }
                        int num13 = 0;
                        int num14 = case5.Whens.Count;
                        while (num13 < num14)
                        {
                            if (!AreSimilar(case5.Whens[num13].Match, case6.Whens[num13].Match))
                            {
                                return(false);
                            }
                            if (!AreSimilar(case5.Whens[num13].TypeBinding, case6.Whens[num13].TypeBinding))
                            {
                                return(false);
                            }
                            num13++;
                        }
                        return(true);
                    }
                    }
                }
                return(false);
            }