예제 #1
0
        public static string GetBackingField(MemberInfo mi)
        {
            System.Reflection.PropertyInfo pi = mi as System.Reflection.PropertyInfo;
                        #if SILVERLIGHT || CF || UNITY3D || WinRT || MONODROID
            string fieldName = SilverlightPropertyResolver.GetPrivateFieldName(pi, pi.DeclaringType);
            if (fieldName != null)
            {
                return(fieldName);
            }
#else
            System.Reflection.FieldInfo fInfo = BackingFieldResolver.GetBackingField(pi);

            if (fInfo != null)
            {
                return(fInfo.Name);
            }
#endif
            else
            {
                string fld = Sqo.Utilities.MetaHelper.GetBackingFieldByAttribute(mi);
                if (fld != null)
                {
                    return(fld);
                }
                else
                {
                    throw new SiaqodbException("A Property must have UseVariable Attribute set");
                }
            }
        }
예제 #2
0
        /// <summary>
        /// プロパティ情報からBackingFieldを取得する.
        /// </summary>
        /// <param name="property">Backing fieldsを取得したいプロパティ情報</param>
        /// <param name="useCache">キャッシュ機能を利用する場合はtrueを指定する. default: true</param>
        /// <returns>Backing fields情報</returns>
        public static FieldInfo GetBackingField(this PropertyInfo property, bool useCache = true)
        {
            if (property == null)
            {
                throw new ArgumentNullException("The argument must be a non-null value.");
            }

            if (useCache && _backingfieldCache.TryGetValue(property, out FieldInfo field))
            {
                return(field);
            }

            field = BackingFieldResolver.GetBackingField(property);
            if (useCache)
            {
                _backingfieldCache.Add(property, field);
            }
            return(field);
        }
예제 #3
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")
                    {
                        joinFieldName = m.Member.Name;
                    }
                    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)
                        {
                            joinFieldName = fieldName;
                        }
                        else
                        {
                            string fld = Sqo.Utilities.MetaHelper.GetBackingFieldByAttribute(m.Member);
                            if (fld != null)
                            {
                                joinFieldName = fld;
                            }
                            else
                            {
                                throw new SiaqodbException("A Property must have UseVariable Attribute set");
                            }
                        }
#else
                        try
                        {
                            System.Reflection.FieldInfo fi = BackingFieldResolver.GetBackingField(pi);
                            if (fi != null)
                            {
                                joinFieldName = fi.Name;
                            }
                        }

                        catch (Exception ex)
                        {
                            string fld = Sqo.Utilities.MetaHelper.GetBackingFieldByAttribute(m.Member);
                            if (fld != null)
                            {
                                joinFieldName = fld;
                            }
                            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
                {
                    joinFieldName = m.Member.Name;
                }
                else
                {
                    throw new NotSupportedException("Unsupported Member Type!");
                }

                return(m);
            }

            throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
        }
예제 #4
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));
            }
        }
예제 #5
0
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            //TODO when member is declared by interface, this would solve, but need to find out implementors of interface to get backing field of property
            //if (m.Expression != null && (m.Expression.NodeType == ExpressionType.Convert || m.Expression.NodeType == ExpressionType.ConvertChecked))
            //{
            //    MemberExpression memExpr= Expression.MakeMemberAccess(((UnaryExpression)m.Expression).Operand ,m.Member) ;
            //   return this.VisitMemberAccess(memExpr);

            //}

            if (m.Expression != null && (m.Expression.NodeType == ExpressionType.Parameter || m.Expression.NodeType == ExpressionType.MemberAccess))
            {
                if (currentWhere == null)
                {
                    if (m.Type == typeof(bool)) //ex: WHERE Active
                    {
                        BinaryExpression exp = BinaryExpression.MakeBinary(ExpressionType.Equal, m, Expression.Constant(true));
                        return(this.VisitBinary(exp));
                    }
                }
#if WinRT
                if (m.Member.GetMemberType() == MemberTypes.Property)
#else
                if (m.Member.MemberType == System.Reflection.MemberTypes.Property)
#endif
                {
                    if (m.Member.Name == "OID")
                    {
                        currentWhere.AttributeName.Add("OID");
                        currentWhere.ParentType.Add(m.Member.DeclaringType);
                    }
                    else
                    {
                        if (m.Member.DeclaringType == typeof(string))
                        {
                            throw new Exceptions.LINQUnoptimizeException(string.Format("The member '{0}' is not supported", m.Member.Name));
                        }
                        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)
                        {
                            currentWhere.AttributeName.Add(fieldName);
                            currentWhere.ParentType.Add(m.Member.DeclaringType);
                        }
                        else
                        {
                            string fld = Sqo.Utilities.MetaHelper.GetBackingFieldByAttribute(m.Member);
                            if (fld != null)
                            {
                                currentWhere.AttributeName.Add(fld);

                                currentWhere.ParentType.Add(m.Member.DeclaringType);
                            }
                            else
                            {
                                throw new SiaqodbException("A Property must have UseVariable Attribute set( property:" + m.Member.Name + " of type:" + m.Member.DeclaringType.ToString() + ")");
                            }
                        }
#else
                        try
                        {
                            System.Reflection.FieldInfo fi = BackingFieldResolver.GetBackingField(pi);
                            if (fi != null)
                            {
                                currentWhere.AttributeName.Add(fi.Name);

                                currentWhere.ParentType.Add(m.Member.DeclaringType);
                            }
                        }
                        catch
                        {
                            string fld = Sqo.Utilities.MetaHelper.GetBackingFieldByAttribute(m.Member);
                            if (fld != null)
                            {
                                currentWhere.AttributeName.Add(fld);

                                currentWhere.ParentType.Add(m.Member.DeclaringType);
                            }
                            else
                            {
                                throw new SiaqodbException("A Property must have UseVariable Attribute set( property:" + m.Member.Name + " of type:" + m.Member.DeclaringType.ToString() + ")");
                            }
                        }
#endif
                    }
                }
#if WinRT
                else if (m.Member.GetMemberType() == MemberTypes.Field)
#else
                else if (m.Member.MemberType == System.Reflection.MemberTypes.Field)
#endif
                {
                    currentWhere.AttributeName.Add(m.Member.Name);
                    currentWhere.ParentType.Add(m.Member.DeclaringType);
                }
                else
                {
                    throw new NotSupportedException("Unsupported Member Type!");
                }

                if (m.Expression.NodeType == ExpressionType.MemberAccess)
                {
                    return(base.VisitMemberAccess(m));
                }
                else
                {
                    return(m);
                }
            }

            throw new  Exceptions.LINQUnoptimizeException(string.Format("The member '{0}' is not supported", m.Member.Name));
        }