Example #1
0
            protected override Expression VisitMemberAccess(MemberExpression m)
            {
                var declaringType = m.Member.DeclaringType;

                if (!TypeHelper.IsNativeToMongo(declaringType) && !IsCollection(declaringType))
                {
                    Expression e;
                    if (_determiner.IsGroupingKey(m))
                    {
                        _fieldParts.Push(m.Member.Name);
                        Visit(m.Expression);
                        return(m);
                    }
                    else if (_memberMap.TryGetValue(m.Member, out e) && e is FieldExpression)
                    {
                        var field = (FieldExpression)e;
                        _fieldParts.Push(field.Name);

                        if (_bsonMemberMap == null)
                        {
                            _bsonMemberMap = field.MemberMap;
                        }

                        Visit(m.Expression);
                        return(m);
                    }
                    else if (e == null)
                    {
                        var classMap = BsonClassMap.LookupClassMap(declaringType);
                        var propMap  = classMap.GetMemberMap(m.Member.Name);
                        if (propMap != null)
                        {
                            _fieldParts.Push(propMap.ElementName);

                            if (_bsonMemberMap == null)
                            {
                                _bsonMemberMap = propMap;
                            }
                        }
                        else
                        {
                            _fieldParts.Push(m.Member.Name);
                        }

                        Visit(m.Expression);
                        return(m);
                    }
                }

                _isBlocked = true;
                return(m);
            }