Example #1
0
        private void AddIndexer()
        {
            int index = this.index;
            int num2  = 1;

            while (num2 > 0)
            {
                if (this.index >= this.pathLength)
                {
                    return;
                }
                if (this.pathValue[this.index] == '[')
                {
                    num2++;
                }
                else if (this.pathValue[this.index] == ']')
                {
                    num2--;
                }
                this.index++;
            }
            string          n    = this.pathValue.Substring(index, (this.index - index) - 1).Trim();
            SourceValueInfo item = new SourceValueInfo(SourceValueType.Indexer, this.drillIn, n);

            this.al.Add(item);
            this.StartNewLevel();
        }
 private void AddIndexer()
 {
     int index = this.index;
     int num2 = 1;
     while (num2 > 0)
     {
         if (this.index >= this.pathLength)
         {
             return;
         }
         if (this.pathValue[this.index] == '[')
         {
             num2++;
         }
         else if (this.pathValue[this.index] == ']')
         {
             num2--;
         }
         this.index++;
     }
     string n = this.pathValue.Substring(index, (this.index - index) - 1).Trim();
     SourceValueInfo item = new SourceValueInfo(SourceValueType.Indexer, this.drillIn, n);
     this.al.Add(item);
     this.StartNewLevel();
 }
 public PathErrorInfoEventArgs(SourceValueInfo info, string currentPath)
 {
     if (currentPath == null)
     {
         throw new ArgumentNullException("currentPath");
     }
     this.info        = info;
     this.currentPath = currentPath;
 }
 private void AddProperty()
 {
     int index = this.index;
     while ((this.index < this.pathLength) && (SpecialChars.IndexOf(this.pathValue[this.index]) < 0))
     {
         this.index++;
     }
     string n = this.pathValue.Substring(index, this.index - index).Trim();
     SourceValueInfo item = new SourceValueInfo(SourceValueType.Property, this.drillIn, n);
     this.al.Add(item);
     this.StartNewLevel();
 }
Example #5
0
        private void AddProperty()
        {
            int index = this.index;

            while ((this.index < this.pathLength) && (SpecialChars.IndexOf(this.pathValue[this.index]) < 0))
            {
                this.index++;
            }
            string          n    = this.pathValue.Substring(index, this.index - index).Trim();
            SourceValueInfo item = new SourceValueInfo(SourceValueType.Property, this.drillIn, n);

            this.al.Add(item);
            this.StartNewLevel();
        }
Example #6
0
 private void AddIndexer()
 {
     int start = this.index;
     int level = 1;
     while (level > 0)
     {
         if (this.index >= this.pathLength)
         {
             return;
         }
         if (this.pathValue[this.index] == '[')
             ++level;
         else if (this.pathValue[this.index] == ']')
             --level;
         ++this.index;
     }
     string name = this.pathValue.Substring(start, this.index - start - 1).Trim();
     SourceValueInfo info = new SourceValueInfo(
                                 SourceValueType.Indexer,
                                 this.drillIn, name);
     this.al.Add(info);
     StartNewLevel();
 }
Example #7
0
        private void AddProperty()
        {
            int start = this.index;
            while (this.index < this.pathLength && SpecialChars.IndexOf(this.pathValue[this.index]) < 0)
                ++this.index;

            string name = this.pathValue.Substring(start, this.index - start).Trim();
            SourceValueInfo info = new SourceValueInfo(
                                        SourceValueType.Property,
                                        this.drillIn, name);
            this.al.Add(info);
            StartNewLevel();
        }
Example #8
0
        internal List<SourceValueInfo> Parse(string path, bool returnResultBeforeError)
        {
            this.pathValue = (path != null) ? path.Trim() : String.Empty;
            this.pathLength = this.pathValue.Length;
            this.index = 0;
            this.drillIn = DrillIn.IfNeeded;

            this.al.Clear();
            this.error = null;
            this.state = State.Init;

            if (this.pathLength > 0 && this.pathValue[0] == '.')
            {
                //empty first prop - > input path was like ".bar"; need to add first empty property
                SourceValueInfo info = new SourceValueInfo(SourceValueType.Property, this.drillIn, string.Empty);
                this.al.Add(info);
            }

            while (this.state != State.Done)
            {
                char c = (this.index < this.pathLength) ? this.pathValue[this.index] : NullChar;
                switch (this.state)
                {
                    case State.Init:
                        switch (c)
                        {
                            case '/':
                            case '.':
                            case '[':
                            case NullChar:
                                this.state = State.Prop;
                                break;
                            case ']'://unexpected close indexer, report error
                                this.error = "path[" + this.index + "] = " + c;
                                return returnResultBeforeError ? this.al : EmptyInfo;

                            default:
                                AddProperty();
                                break;
                        }
                        break;

                    case State.Prop:
                        bool isIndexer = false;
                        switch (c)
                        {
                            case '.':
                                this.drillIn = DrillIn.Never;
                                break;
                            case '[':
                                isIndexer = true;
                                break;
                            case NullChar:
                                --this.index;
                                break;
                            default:
                                this.error = "path[" + this.index + "] = " + c;
                                return returnResultBeforeError ? this.al : EmptyInfo;
                        }
                        ++this.index;      // skip over special character
                        if (isIndexer)
                            AddIndexer();
                        else
                            AddProperty();
                        break;
                }
            }

            return (this.error == null || returnResultBeforeError) ? this.al : EmptyInfo;
        }
Example #9
0
        public PathErrorInfoEventArgs(SourceValueInfo info, string currentPath)
        {
            if (currentPath == null)
                throw new ArgumentNullException("currentPath");

            this.info = info;
            this.currentPath = currentPath;
        }
Example #10
0
        internal List <SourceValueInfo> Parse(string path, bool returnResultBeforeError)
        {
            this.pathValue  = (path != null) ? path.Trim() : string.Empty;
            this.pathLength = this.pathValue.Length;
            this.index      = 0;
            this.drillIn    = DrillIn.IfNeeded;
            this.al.Clear();
            this.error = null;
            this.state = State.Init;
            if ((this.pathLength > 0) && (this.pathValue[0] == '.'))
            {
                SourceValueInfo item = new SourceValueInfo(SourceValueType.Property, this.drillIn, string.Empty);
                this.al.Add(item);
            }
            while (this.state != State.Done)
            {
                bool flag;
                char ch = (this.index < this.pathLength) ? this.pathValue[this.index] : '\0';
                switch (this.state)
                {
                case State.Init:
                    switch (ch)
                    {
                    case ']':
                        goto Label_010C;
                    }
                    goto Label_015C;

                case State.Prop:
                    flag = false;
                    switch (ch)
                    {
                    case '\0':
                        goto Label_018C;

                    case '.':
                        goto Label_017F;

                    case '[':
                        goto Label_0188;
                    }
                    goto Label_019C;

                default:
                {
                    continue;
                }
                }
                this.state = State.Prop;
                continue;
                Label_010C :;
                this.error = string.Concat(new object[] { "path[", this.index, "] = ", ch });
                if (!returnResultBeforeError)
                {
                    return(EmptyInfo);
                }
                return(this.al);

Label_015C:
                this.AddProperty();
                continue;
Label_017F:
                this.drillIn = DrillIn.Never;
                goto Label_01EC;
Label_0188:
                flag = true;
                goto Label_01EC;
Label_018C:
                this.index--;
                goto Label_01EC;
                Label_019C :;
                this.error = string.Concat(new object[] { "path[", this.index, "] = ", ch });
                if (!returnResultBeforeError)
                {
                    return(EmptyInfo);
                }
                return(this.al);

Label_01EC:
                this.index++;
                if (flag)
                {
                    this.AddIndexer();
                }
                else
                {
                    this.AddProperty();
                }
            }
            if ((this.error != null) && !returnResultBeforeError)
            {
                return(EmptyInfo);
            }
            return(this.al);
        }
        public bool TryWalkPropertyPath(Type rootType, string path)
        {
            if (rootType == null)
            {
                throw new ArgumentNullException("rootType");
            }
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            Type                   type        = rootType;
            string                 currentPath = string.Empty;
            PathParser             parser      = new PathParser();
            List <SourceValueInfo> list        = parser.Parse(path, true);
            string                 error       = parser.Error;

            for (int i = 0; i < list.Count; i++)
            {
                MemberInfo[]            infoArray;
                PropertyInfo            info7;
                PathMemberInfoEventArgs args5;
                SourceValueInfo         info = list[i];
                if (string.IsNullOrEmpty(info.name))
                {
                    if (this.PathErrorFound != null)
                    {
                        this.PathErrorFound(this, new PathErrorInfoEventArgs(info, currentPath));
                    }
                    return(false);
                }
                string     str3         = (info.type == SourceValueType.Property) ? info.name : ("[" + info.name + "]");
                string     str4         = string.IsNullOrEmpty(currentPath) ? str3 : (currentPath + ((info.type == SourceValueType.Property) ? "." : string.Empty) + str3);
                Type       propertyType = null;
                MemberInfo memberInfo   = null;
                switch (info.type)
                {
                case SourceValueType.Property:
                    infoArray = PopulateMembers(type, info.name);
                    if (((infoArray != null) && (infoArray.Length != 0)) && (infoArray[0] != null))
                    {
                        break;
                    }
                    if (this.PathErrorFound != null)
                    {
                        this.PathErrorFound(this, new PathErrorInfoEventArgs(info, currentPath));
                    }
                    return(false);

                case SourceValueType.Indexer:
                {
                    if (string.IsNullOrEmpty(info.name))
                    {
                        goto Label_04AC;
                    }
                    string[] aryArgName = info.name.Split(new char[] { ',' });
                    object[] objArray2  = new object[aryArgName.Length];
                    info7 = BindHelpers.GetMatchedPropertyInfo(type, aryArgName, objArray2);
                    if (info7 == null)
                    {
                        goto Label_048E;
                    }
                    if (this.MemberFound == null)
                    {
                        goto Label_046B;
                    }
                    args5 = new PathMemberInfoEventArgs(str4, type, info7, PathMemberKind.Index, i == (list.Count - 1), objArray2);
                    this.MemberFound(this, args5);
                    if (args5.Action != PathWalkAction.Cancel)
                    {
                        goto Label_045F;
                    }
                    return(false);
                }

                default:
                    goto Label_04CA;
                }
                memberInfo = infoArray[0];
                if ((memberInfo is EventInfo) || (memberInfo is MethodInfo))
                {
                    if (this.MemberFound != null)
                    {
                        PathMemberInfoEventArgs e = new PathMemberInfoEventArgs(str4, type, memberInfo, PathMemberKind.Event, i == (list.Count - 1));
                        this.MemberFound(this, e);
                        if (e.Action == PathWalkAction.Cancel)
                        {
                            return(false);
                        }
                        if (e.Action == PathWalkAction.Stop)
                        {
                            return(true);
                        }
                    }
                    return(string.IsNullOrEmpty(error));
                }
                if (memberInfo is PropertyInfo)
                {
                    PropertyInfo             originalPropertyInfo = memberInfo as PropertyInfo;
                    MethodInfo               getMethod            = originalPropertyInfo.GetGetMethod();
                    MethodInfo               setMethod            = originalPropertyInfo.GetSetMethod();
                    ActivityBindPropertyInfo info6 = new ActivityBindPropertyInfo(type, getMethod, setMethod, originalPropertyInfo.Name, originalPropertyInfo);
                    propertyType = info6.PropertyType;
                    if (info6.GetIndexParameters().Length <= 0)
                    {
                        if (this.MemberFound != null)
                        {
                            PathMemberInfoEventArgs args3 = new PathMemberInfoEventArgs(str4, type, info6, PathMemberKind.Property, i == (list.Count - 1));
                            this.MemberFound(this, args3);
                            if (args3.Action == PathWalkAction.Cancel)
                            {
                                return(false);
                            }
                            if (args3.Action == PathWalkAction.Stop)
                            {
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        if (((i >= (list.Count - 1)) || (list[i + 1].type != SourceValueType.Indexer)) || string.IsNullOrEmpty(list[i + 1].name))
                        {
                            if (this.PathErrorFound != null)
                            {
                                this.PathErrorFound(this, new PathErrorInfoEventArgs(info, currentPath));
                            }
                            return(false);
                        }
                        string[] argNames = list[i + 1].name.Split(new char[] { ',' });
                        object[] args     = new object[argNames.Length];
                        if (!BindHelpers.MatchIndexerParameters(info6, argNames, args))
                        {
                            if (this.PathErrorFound != null)
                            {
                                this.PathErrorFound(this, new PathErrorInfoEventArgs(info, currentPath));
                            }
                            return(false);
                        }
                        str4 = str4 + "[" + list[i + 1].name + "]";
                        if (this.MemberFound != null)
                        {
                            PathMemberInfoEventArgs args2 = new PathMemberInfoEventArgs(str4, type, info6, PathMemberKind.IndexedProperty, i == (list.Count - 2), args);
                            this.MemberFound(this, args2);
                            if (args2.Action == PathWalkAction.Cancel)
                            {
                                return(false);
                            }
                            if (args2.Action == PathWalkAction.Stop)
                            {
                                return(true);
                            }
                        }
                        i++;
                    }
                }
                else
                {
                    if (this.MemberFound != null)
                    {
                        PathMemberInfoEventArgs args4 = new PathMemberInfoEventArgs(str4, type, memberInfo, PathMemberKind.Field, i == (list.Count - 1));
                        this.MemberFound(this, args4);
                        if (args4.Action == PathWalkAction.Cancel)
                        {
                            return(false);
                        }
                        if (args4.Action == PathWalkAction.Stop)
                        {
                            return(true);
                        }
                    }
                    propertyType = (memberInfo as FieldInfo).FieldType;
                }
                goto Label_04CA;
Label_045F:
                if (args5.Action == PathWalkAction.Stop)
                {
                    return(true);
                }
Label_046B:
                propertyType = info7.PropertyType;
                if (propertyType == null)
                {
                    propertyType = info7.GetGetMethod().ReturnType;
                }
                goto Label_04CA;
Label_048E:
                if (this.PathErrorFound != null)
                {
                    this.PathErrorFound(this, new PathErrorInfoEventArgs(info, currentPath));
                }
                return(false);

Label_04AC:
                if (this.PathErrorFound != null)
                {
                    this.PathErrorFound(this, new PathErrorInfoEventArgs(info, currentPath));
                }
                return(false);

Label_04CA:
                type        = propertyType;
                currentPath = str4;
            }
            return(string.IsNullOrEmpty(error));
        }
        internal List<SourceValueInfo> Parse(string path, bool returnResultBeforeError)
        {
            this.pathValue = (path != null) ? path.Trim() : string.Empty;
            this.pathLength = this.pathValue.Length;
            this.index = 0;
            this.drillIn = DrillIn.IfNeeded;
            this.al.Clear();
            this.error = null;
            this.state = State.Init;
            if ((this.pathLength > 0) && (this.pathValue[0] == '.'))
            {
                SourceValueInfo item = new SourceValueInfo(SourceValueType.Property, this.drillIn, string.Empty);
                this.al.Add(item);
            }
            while (this.state != State.Done)
            {
                bool flag;
                char ch = (this.index < this.pathLength) ? this.pathValue[this.index] : '\0';
                switch (this.state)
                {
                    case State.Init:
                        switch (ch)
                        {
                            case ']':
                                goto Label_010C;
                        }
                        goto Label_015C;

                    case State.Prop:
                        flag = false;
                        switch (ch)
                        {
                            case '\0':
                                goto Label_018C;

                            case '.':
                                goto Label_017F;

                            case '[':
                                goto Label_0188;
                        }
                        goto Label_019C;

                    default:
                    {
                        continue;
                    }
                }
                this.state = State.Prop;
                continue;
            Label_010C:;
                this.error = string.Concat(new object[] { "path[", this.index, "] = ", ch });
                if (!returnResultBeforeError)
                {
                    return EmptyInfo;
                }
                return this.al;
            Label_015C:
                this.AddProperty();
                continue;
            Label_017F:
                this.drillIn = DrillIn.Never;
                goto Label_01EC;
            Label_0188:
                flag = true;
                goto Label_01EC;
            Label_018C:
                this.index--;
                goto Label_01EC;
            Label_019C:;
                this.error = string.Concat(new object[] { "path[", this.index, "] = ", ch });
                if (!returnResultBeforeError)
                {
                    return EmptyInfo;
                }
                return this.al;
            Label_01EC:
                this.index++;
                if (flag)
                {
                    this.AddIndexer();
                }
                else
                {
                    this.AddProperty();
                }
            }
            if ((this.error != null) && !returnResultBeforeError)
            {
                return EmptyInfo;
            }
            return this.al;
        }