コード例 #1
0
        private Tuple <bool, Expr> IsMatch(FluentPluginHelper helper, Type type, Token klass, Token instance, Token prop, Token method)
        {
            var memberName = string.Empty;
            var rootVar    = string.Empty;
            var match      = false;
            var nameToken  = klass;

            // 1. Class property
            if (klass != null && prop != null)
            {
                rootVar = klass.Text;
                if (helper.IsClassProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                }
            }
            // 2. Class method
            else if (klass != null && method != null)
            {
                rootVar = type.Name;
                if (helper.IsClassMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                }
            }
            // 3. Instance property
            else if (instance != null && prop != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                    nameToken  = instance;
                }
            }
            // 4. Instance method
            else if (instance != null && method != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                    nameToken  = instance;
                }
            }
            if (!match)
            {
                return(new Tuple <bool, Expr>(false, null));
            }

            var varExp = Exprs.Ident(rootVar, null);
            var memExp = Exprs.MemberAccess(varExp, memberName, false, null);

            return(new Tuple <bool, Expr>(memberName != null, memExp));
        }
コード例 #2
0
        private Tuple <bool, Expr> IsMatch(FluentPluginHelper helper, Type type, Token klass, Token instance, Token prop, Token method)
        {
            string memberName = null;
            string rootVar    = null;
            bool   match      = false;

            // 1. Class property
            if (klass != null && prop != null)
            {
                rootVar = klass.Text;
                if (helper.IsClassProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                }
            }
            // 2. Class method
            else if (klass != null && method != null)
            {
                rootVar = type.Name;
                if (helper.IsClassMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                }
            }
            // 3. Instance property
            else if (instance != null && prop != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                }
            }
            // 4. Instance method
            else if (instance != null && method != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                }
            }
            if (!match)
            {
                return(new Tuple <bool, Expr>(false, null));
            }

            var varExp = new VariableExpr(rootVar);

            varExp.Ctx = _parser.Context;
            var memExp = new MemberAccessExpr(varExp, memberName, false);

            memExp.Ctx = _parser.Context;
            return(new Tuple <bool, Expr>(memberName != null, memExp));
        }
コード例 #3
0
        private Tuple<bool, Expr> IsMatch(FluentPluginHelper helper, Type type, Token klass, Token instance, Token prop, Token method)
        {
            var memberName = string.Empty;
            var rootVar = string.Empty;
            var match = false;
            var nameToken = klass;

            // 1. Class property
            if (klass != null && prop != null)
            {
                rootVar = klass.Text;
                if (helper.IsClassProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match = true;
                }
            }
            // 2. Class method
            else if (klass != null && method != null)
            {
                rootVar = type.Name;
                if (helper.IsClassMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match = true;
                }
            }
            // 3. Instance property
            else if (instance != null && prop != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match = true;
                    nameToken = instance;
                }
            }
            // 4. Instance method
            else if (instance != null && method != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match = true;
                    nameToken = instance;
                }
            }
            if (!match)
                return new Tuple<bool, Expr>(false, null);

            var varExp = _parser.ToIdentExpr(rootVar, null);
            var memExp = _parser.ToMemberAccessExpr(varExp, memberName, false, null);
            return new Tuple<bool, Expr>(memberName != null, memExp);
        }