Beispiel #1
0
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter)
            {
#if WinRT
                if (m.Member.GetMemberType() == MemberTypes.Property)
#else
                if (m.Member.MemberType == System.Reflection.MemberTypes.Property)
#endif
                {
                    if (m.Member.Name == "OID")
                    {
                        SqoColumn col = new SqoColumn();
                        col.SourcePropName = m.Member.Name;
                        col.SourceType     = m.Expression.Type;
                        this.columns.Add(col);
                        return(Expression.Convert(Expression.Call(this.row, miGetValue, Expression.Constant(iColumn++)), m.Type));
                    }
                    else
                    {
                        System.Reflection.PropertyInfo pi = m.Member as System.Reflection.PropertyInfo;
                                                #if SILVERLIGHT || CF || UNITY3D || WinRT || MONODROID
                        string fieldName = SilverlightPropertyResolver.GetPrivateFieldName(pi, pi.DeclaringType);
                        if (fieldName != null)
                        {
                            SqoColumn col = new SqoColumn();
                            col.SourcePropName = fieldName;
                            col.SourceType     = m.Expression.Type;
                            this.columns.Add(col);
                            return(Expression.Convert(Expression.Call(this.row, miGetValue, Expression.Constant(iColumn++)), m.Type));
                        }
                        else
                        {
                            string fld = MetaHelper.GetBackingFieldByAttribute(m.Member);
                            if (fld != null)
                            {
                                SqoColumn col = new SqoColumn();
                                col.SourcePropName = fld;
                                col.SourceType     = m.Expression.Type;
                                this.columns.Add(col);
                                return(Expression.Convert(Expression.Call(this.row, miGetValue, Expression.Constant(iColumn++)), m.Type));
                            }
                            else
                            {
                                throw new SiaqodbException("A Property must have UseVariable Attribute set");
                            }
                        }
#else
                        try
                        {
                            System.Reflection.FieldInfo fi = BackingFieldResolver.GetBackingField(pi);
                            if (fi != null)
                            {
                                SqoColumn col = new SqoColumn();
                                col.SourcePropName = fi.Name;
                                col.SourceType     = m.Expression.Type;
                                this.columns.Add(col);
                                return(Expression.Convert(Expression.Call(this.row, miGetValue, Expression.Constant(iColumn++)), m.Type));
                            }
                            else
                            {
                                throw  new SiaqodbException("A Property must have UseVariable Attribute set");
                            }
                        }
                        catch
                        {
                            string fld = Sqo.Utilities.MetaHelper.GetBackingFieldByAttribute(m.Member);
                            if (fld != null)
                            {
                                SqoColumn col = new SqoColumn();
                                col.SourcePropName = fld;
                                col.SourceType     = m.Expression.Type;
                                this.columns.Add(col);
                                return(Expression.Convert(Expression.Call(this.row, miGetValue, Expression.Constant(iColumn++)), m.Type));
                            }
                            else
                            {
                                throw new SiaqodbException("A Property must have UseVariable Attribute set");
                            }
                        }
#endif
                    }
                }
#if WinRT
                else if (m.Member.GetMemberType() == MemberTypes.Field)
#else
                else if (m.Member.MemberType == System.Reflection.MemberTypes.Field)
#endif
                {
                    SqoColumn col = new SqoColumn();
                    col.SourcePropName = m.Member.Name;
                    col.SourceType     = m.Expression.Type;
                    this.columns.Add(col);
                    return(Expression.Convert(Expression.Call(this.row, miGetValue, Expression.Constant(iColumn++)), m.Type));
                }
                else
                {
                    throw new NotSupportedException("Not supported Member Type!");
                }
            }
            else
            {
                return(base.VisitMemberAccess(m));
            }
        }