Пример #1
0
 internal void ReportGetValueError(int k, object item, Exception ex)
 {
     if (TraceData.IsEnabled)
     {
         SourceValueInfo svi        = PW.GetSourceValueInfo(k);
         Type            type       = PW.GetType(k);
         string          parentName = (k > 0)? PW.GetSourceValueInfo(k - 1).name : String.Empty;
         TraceData.Trace(ParentBindingExpression.TraceLevel,
                         TraceData.CannotGetClrRawValue(
                             svi.propertyName, type.Name,
                             parentName, AvTrace.TypeName(item)),
                         ParentBindingExpression, ex);
     }
 }
Пример #2
0
 internal void ReportSetValueError(int k, object item, object value, Exception ex)
 {
     if (TraceData.IsEnabled)
     {
         SourceValueInfo svi  = PW.GetSourceValueInfo(k);
         Type            type = PW.GetType(k);
         TraceData.Trace(TraceEventType.Error,
                         TraceData.CannotSetClrRawValue(
                             svi.propertyName, type.Name,
                             AvTrace.TypeName(item),
                             AvTrace.ToStringHelper(value),
                             AvTrace.TypeName(value)),
                         ParentBindingExpression, ex);
     }
 }
Пример #3
0
 // Token: 0x06007485 RID: 29829 RVA: 0x002156DC File Offset: 0x002138DC
 internal void ReportGetValueError(int k, object item, Exception ex)
 {
     if (TraceData.IsEnabled)
     {
         SourceValueInfo sourceValueInfo = this.PW.GetSourceValueInfo(k);
         Type            type            = this.PW.GetType(k);
         string          text            = (k > 0) ? this.PW.GetSourceValueInfo(k - 1).name : string.Empty;
         TraceData.Trace(base.ParentBindingExpression.TraceLevel, TraceData.CannotGetClrRawValue(new object[]
         {
             sourceValueInfo.propertyName,
             type.Name,
             text,
             AvTrace.TypeName(item)
         }), base.ParentBindingExpression, ex);
     }
 }
Пример #4
0
        void AddProperty()
        {
            int start = _index;
            int level = 0;

            // include leading dots in the path (for XLinq)
            while (_index < _n && _path[_index] == '.')
            {
                ++_index;
            }

            while (_index < _n && (level > 0 || SpecialChars.IndexOf(_path[_index]) < 0))
            {
                if (_path[_index] == '(')
                {
                    ++level;
                }
                else if (_path[_index] == ')')
                {
                    --level;
                }

                ++_index;
            }

            if (level > 0)
            {
                SetError(SRID.UnmatchedParen, _path.Substring(start));
                return;
            }

            if (level < 0)
            {
                SetError(SRID.UnmatchedParen, _path.Substring(0, _index));
                return;
            }

            string name = _path.Substring(start, _index - start).Trim();

            SourceValueInfo info = (name.Length > 0)
                ? new SourceValueInfo(SourceValueType.Property, _drillIn, name)
                : new SourceValueInfo(SourceValueType.Direct, _drillIn, (string)null);

            _al.Add(info);

            StartNewLevel();
        }
        // Token: 0x06007626 RID: 30246 RVA: 0x0021AE18 File Offset: 0x00219018
        private void AddProperty()
        {
            int index = this._index;
            int num   = 0;

            while (this._index < this._n)
            {
                if (this._path[this._index] != '.')
                {
                    break;
                }
                this._index++;
            }
            while (this._index < this._n && (num > 0 || PathParser.SpecialChars.IndexOf(this._path[this._index]) < 0))
            {
                if (this._path[this._index] == '(')
                {
                    num++;
                }
                else if (this._path[this._index] == ')')
                {
                    num--;
                }
                this._index++;
            }
            if (num > 0)
            {
                this.SetError("UnmatchedParen", new object[]
                {
                    this._path.Substring(index)
                });
                return;
            }
            if (num < 0)
            {
                this.SetError("UnmatchedParen", new object[]
                {
                    this._path.Substring(0, this._index)
                });
                return;
            }
            string          text            = this._path.Substring(index, this._index - index).Trim();
            SourceValueInfo sourceValueInfo = (text.Length > 0) ? new SourceValueInfo(SourceValueType.Property, this._drillIn, text) : new SourceValueInfo(SourceValueType.Direct, this._drillIn, null);

            this._al.Add(sourceValueInfo);
            this.StartNewLevel();
        }
Пример #6
0
        // Each level of the path consists of
        //      a property or indexer:
        //                  .propname
        //                  /propname
        //                  [index]
        //                  /[index]
        //          (The . or / is optional in the very first level.)
        // The parser is a finite-state machine with two states corresponding
        // to the two-character lookahead above, plus two more states for the begining
        // and end.  The state transistions are done explicitly in the code below.
        //
        // The parser returns a 0-length array if it finds a syntax error.
        // It sets the Error property, so the caller can find out what happened.

        public SourceValueInfo[] Parse(string path)
        {
            _path = (path != null) ? path.Trim() : String.Empty;
            _n = _path.Length;

            if (_n == 0)
            {
                // When no path string is specified, use value directly and do not drill-in. (same as Path=".")
                // ClrBindingWorker needs this information to tell XmlBindingWorker about collectionMode.
                return new SourceValueInfo[] { new SourceValueInfo(SourceValueType.Direct, DrillIn.Never, (string)null) };
            }

            _index = 0;
            _drillIn = DrillIn.IfNeeded;

            _al.Clear();
            _error = null;
            _state = State.Init;

            while (_state != State.Done)
            {
                char c = (_index<_n) ? _path[_index] : NullChar;
                if (Char.IsWhiteSpace(c))
                {
                    ++ _index;
                    continue;
                }

                switch (_state)
                {
                case State.Init:
                    switch (c)
                    {
                    case '/':
                    case '.':
                    case NullChar:
                        _state = State.DrillIn;
                        break;
                    default:
                        _state = State.Prop;
                        break;
                    }
                    break;

                case State.DrillIn:
                    switch (c)
                    {
                    case '/':
                        _drillIn = DrillIn.Always;
                        ++ _index;
                        break;
                    case '.':
                        _drillIn = DrillIn.Never;
                        ++ _index;
                        break;
                    case '[':
                    case NullChar:
                        break;
                    default:
                        SetError(SRID.PathSyntax, _path.Substring(0, _index), _path.Substring(_index));
                        return EmptyInfo;
                    }
                    _state = State.Prop;
                    break;

                case State.Prop:
                    bool isIndexer = false;
                    switch (c)
                    {
                    case '[':
                        isIndexer = true;
                        break;
                    default:
                        break;
                    }

                    if (isIndexer)
                        AddIndexer();
                    else
                        AddProperty();

                    break;
                }
            }


            SourceValueInfo[] result;

            if (_error == null)
            {
                result = new SourceValueInfo[_al.Count];
                _al.CopyTo(result);
            }
            else
            {
                result = EmptyInfo;
            }

            return result;
        }
Пример #7
0
        void AddIndexer()
        {
            // indexer args are parsed by a (sub-) state machine with four
            // states.  The string is a comma-separated list of params, each
            // of which has two parts:  a "paren string" and a "value string"
            // (both parts are optional).  The character ^ can be used to
            // escape any of the special characters:  comma, parens, ], ^,
            // and white space.

            int start = ++_index;       // skip over initial [
            int level = 1;              // level of nested []

            bool escaped = false;       // true if current char is escaped
            bool trimRight = false;     // true if value string has trailing white space

            StringBuilder parenStringBuilder = new StringBuilder();
            StringBuilder valueStringBuilder = new StringBuilder();

            FrugalObjectList<IndexerParamInfo> paramList = new FrugalObjectList<IndexerParamInfo>();

            IndexerState state = IndexerState.BeginParam;
            while (state != IndexerState.Done)
            {
                if (_index >= _n)
                {
                    SetError(SRID.UnmatchedBracket, _path.Substring(start - 1));
                    return;
                }

                Char c = _path[_index++];

                // handle the escape character - set the flag for the next character
                if (c == EscapeChar && !escaped)
                {
                    escaped = true;
                    continue;
                }

                switch (state)
                {
                    case IndexerState.BeginParam:   // look for optional (...)
                        if (escaped)
                        {
                            // no '(', go parse the value
                            state = IndexerState.ValueString;
                            goto case IndexerState.ValueString;
                        }
                        else if (c == '(')
                        {
                            // '(' introduces optional paren string
                            state = IndexerState.ParenString;
                        }
                        else if (Char.IsWhiteSpace(c))
                        {
                            // ignore leading white space
                        }
                        else
                        {
                            // no '(', go parse the value
                            state = IndexerState.ValueString;
                            goto case IndexerState.ValueString;
                        }
                        break;

                    case IndexerState.ParenString:  // parse (...)
                        if (escaped)
                        {
                            // add an escaped character without question
                            parenStringBuilder.Append(c);
                        }
                        else if (c == ')')
                        {
                            // end of (...), start to parse value
                            state = IndexerState.ValueString;
                        }
                        else
                        {
                            // add normal characters inside (...)
                            parenStringBuilder.Append(c);
                        }
                        break;

                    case IndexerState.ValueString:  // parse value
                        if (escaped)
                        {
                            // add an escaped character without question
                            valueStringBuilder.Append(c);
                            trimRight = false;
                        }
                        else if (level > 1)
                        {
                            // inside nested [], add characters without question
                            valueStringBuilder.Append(c);
                            trimRight = false;

                            if (c == ']')
                            {
                                --level;
                            }
                        }
                        else if (Char.IsWhiteSpace(c))
                        {
                            // add white space, but trim it later if it's trailing
                            valueStringBuilder.Append(c);
                            trimRight = true;
                        }
                        else if (c == ',' || c == ']')
                        {
                            // end of current paramater - assemble the two parts
                            string parenString = parenStringBuilder.ToString();
                            string valueString = valueStringBuilder.ToString();
                            if (trimRight)
                            {
                                valueString = valueString.TrimEnd();
                            }

                            // add the parts to the final result
                            paramList.Add(new IndexerParamInfo(parenString, valueString));

                            // reset for the next parameter
                            parenStringBuilder.Length = 0;
                            valueStringBuilder.Length = 0;
                            trimRight = false;

                            // after ',' parse next parameter;  after ']' we're done
                            state = (c == ']') ? IndexerState.Done : IndexerState.BeginParam;
                        }
                        else
                        {
                            // add normal characters
                            valueStringBuilder.Append(c);
                            trimRight = false;

                            // keep track of nested []
                            if (c == '[')
                            {
                                ++level;
                            }
                        }
                        break;
                }

                // after processing each character, clear the escape flag
                escaped = false;
            }

            // assemble the final result
            SourceValueInfo info = new SourceValueInfo(
                                        SourceValueType.Indexer,
                                        _drillIn, paramList);
            _al.Add(info);

            StartNewLevel();
        }
Пример #8
0
        // Each level of the path consists of
        //      a property or indexer:
        //                  .propname
        //                  /propname
        //                  [index]
        //                  /[index]
        //          (The . or / is optional in the very first level.)
        // The parser is a finite-state machine with two states corresponding
        // to the two-character lookahead above, plus two more states for the begining
        // and end.  The state transistions are done explicitly in the code below.
        //
        // The parser returns a 0-length array if it finds a syntax error.
        // It sets the Error property, so the caller can find out what happened.

        public SourceValueInfo[] Parse(string path)
        {
            _path = (path != null) ? path.Trim() : String.Empty;
            _n    = _path.Length;

            if (_n == 0)
            {
                // When no path string is specified, use value directly and do not drill-in. (same as Path=".")
                // ClrBindingWorker needs this information to tell XmlBindingWorker about collectionMode.
                return(new SourceValueInfo[] { new SourceValueInfo(SourceValueType.Direct, DrillIn.Never, (string)null) });
            }

            _index   = 0;
            _drillIn = DrillIn.IfNeeded;

            _al.Clear();
            _error = null;
            _state = State.Init;

            while (_state != State.Done)
            {
                char c = (_index < _n) ? _path[_index] : NullChar;
                if (Char.IsWhiteSpace(c))
                {
                    ++_index;
                    continue;
                }

                switch (_state)
                {
                case State.Init:
                    switch (c)
                    {
                    case '/':
                    case '.':
                    case NullChar:
                        _state = State.DrillIn;
                        break;

                    default:
                        _state = State.Prop;
                        break;
                    }
                    break;

                case State.DrillIn:
                    switch (c)
                    {
                    case '/':
                        _drillIn = DrillIn.Always;
                        ++_index;
                        break;

                    case '.':
                        _drillIn = DrillIn.Never;
                        ++_index;
                        break;

                    case '[':
                    case NullChar:
                        break;

                    default:
                        SetError(SRID.PathSyntax, _path.Substring(0, _index), _path.Substring(_index));
                        return(EmptyInfo);
                    }
                    _state = State.Prop;
                    break;

                case State.Prop:
                    bool isIndexer = false;
                    switch (c)
                    {
                    case '[':
                        isIndexer = true;
                        break;

                    default:
                        break;
                    }

                    if (isIndexer)
                    {
                        AddIndexer();
                    }
                    else
                    {
                        AddProperty();
                    }

                    break;
                }
            }


            SourceValueInfo[] result;

            if (_error == null)
            {
                result = new SourceValueInfo[_al.Count];
                _al.CopyTo(result);
            }
            else
            {
                result = EmptyInfo;
            }

            return(result);
        }
Пример #9
0
        void AddIndexer()
        {
            // indexer args are parsed by a (sub-) state machine with four
            // states.  The string is a comma-separated list of params, each
            // of which has two parts:  a "paren string" and a "value string"
            // (both parts are optional).  The character ^ can be used to
            // escape any of the special characters:  comma, parens, ], ^,
            // and white space.

            int start = ++_index;       // skip over initial [
            int level = 1;              // level of nested []

            bool escaped   = false;     // true if current char is escaped
            bool trimRight = false;     // true if value string has trailing white space

            StringBuilder parenStringBuilder = new StringBuilder();
            StringBuilder valueStringBuilder = new StringBuilder();

            FrugalObjectList <IndexerParamInfo> paramList = new FrugalObjectList <IndexerParamInfo>();

            IndexerState state = IndexerState.BeginParam;

            while (state != IndexerState.Done)
            {
                if (_index >= _n)
                {
                    SetError(SRID.UnmatchedBracket, _path.Substring(start - 1));
                    return;
                }

                Char c = _path[_index++];

                // handle the escape character - set the flag for the next character
                if (c == EscapeChar && !escaped)
                {
                    escaped = true;
                    continue;
                }

                switch (state)
                {
                case IndexerState.BeginParam:       // look for optional (...)
                    if (escaped)
                    {
                        // no '(', go parse the value
                        state = IndexerState.ValueString;
                        goto case IndexerState.ValueString;
                    }
                    else if (c == '(')
                    {
                        // '(' introduces optional paren string
                        state = IndexerState.ParenString;
                    }
                    else if (Char.IsWhiteSpace(c))
                    {
                        // ignore leading white space
                    }
                    else
                    {
                        // no '(', go parse the value
                        state = IndexerState.ValueString;
                        goto case IndexerState.ValueString;
                    }
                    break;

                case IndexerState.ParenString:      // parse (...)
                    if (escaped)
                    {
                        // add an escaped character without question
                        parenStringBuilder.Append(c);
                    }
                    else if (c == ')')
                    {
                        // end of (...), start to parse value
                        state = IndexerState.ValueString;
                    }
                    else
                    {
                        // add normal characters inside (...)
                        parenStringBuilder.Append(c);
                    }
                    break;

                case IndexerState.ValueString:      // parse value
                    if (escaped)
                    {
                        // add an escaped character without question
                        valueStringBuilder.Append(c);
                        trimRight = false;
                    }
                    else if (level > 1)
                    {
                        // inside nested [], add characters without question
                        valueStringBuilder.Append(c);
                        trimRight = false;

                        if (c == ']')
                        {
                            --level;
                        }
                    }
                    else if (Char.IsWhiteSpace(c))
                    {
                        // add white space, but trim it later if it's trailing
                        valueStringBuilder.Append(c);
                        trimRight = true;
                    }
                    else if (c == ',' || c == ']')
                    {
                        // end of current paramater - assemble the two parts
                        string parenString = parenStringBuilder.ToString();
                        string valueString = valueStringBuilder.ToString();
                        if (trimRight)
                        {
                            valueString = valueString.TrimEnd();
                        }

                        // add the parts to the final result
                        paramList.Add(new IndexerParamInfo(parenString, valueString));

                        // reset for the next parameter
                        parenStringBuilder.Length = 0;
                        valueStringBuilder.Length = 0;
                        trimRight = false;

                        // after ',' parse next parameter;  after ']' we're done
                        state = (c == ']') ? IndexerState.Done : IndexerState.BeginParam;
                    }
                    else
                    {
                        // add normal characters
                        valueStringBuilder.Append(c);
                        trimRight = false;

                        // keep track of nested []
                        if (c == '[')
                        {
                            ++level;
                        }
                    }
                    break;
                }

                // after processing each character, clear the escape flag
                escaped = false;
            }

            // assemble the final result
            SourceValueInfo info = new SourceValueInfo(
                SourceValueType.Indexer,
                _drillIn, paramList);

            _al.Add(info);

            StartNewLevel();
        }
        // Token: 0x06007625 RID: 30245 RVA: 0x0021AC30 File Offset: 0x00218E30
        public SourceValueInfo[] Parse(string path)
        {
            this._path = ((path != null) ? path.Trim() : string.Empty);
            this._n    = this._path.Length;
            if (this._n == 0)
            {
                return(new SourceValueInfo[]
                {
                    new SourceValueInfo(SourceValueType.Direct, DrillIn.Never, null)
                });
            }
            this._index   = 0;
            this._drillIn = DrillIn.IfNeeded;
            this._al.Clear();
            this._error = null;
            this._state = PathParser.State.Init;
            while (this._state != PathParser.State.Done)
            {
                char c = (this._index < this._n) ? this._path[this._index] : '\0';
                if (char.IsWhiteSpace(c))
                {
                    this._index++;
                }
                else
                {
                    switch (this._state)
                    {
                    case PathParser.State.Init:
                        if (c == '\0' || c == '.' || c == '/')
                        {
                            this._state = PathParser.State.DrillIn;
                        }
                        else
                        {
                            this._state = PathParser.State.Prop;
                        }
                        break;

                    case PathParser.State.DrillIn:
                        if (c <= '.')
                        {
                            if (c != '\0')
                            {
                                if (c != '.')
                                {
                                    goto IL_13E;
                                }
                                this._drillIn = DrillIn.Never;
                                this._index++;
                            }
                        }
                        else if (c != '/')
                        {
                            if (c != '[')
                            {
                                goto IL_13E;
                            }
                        }
                        else
                        {
                            this._drillIn = DrillIn.Always;
                            this._index++;
                        }
                        this._state = PathParser.State.Prop;
                        break;
IL_13E:
                        this.SetError("PathSyntax", new object[]
                        {
                            this._path.Substring(0, this._index),
                            this._path.Substring(this._index)
                        });
                        return(PathParser.EmptyInfo);

                    case PathParser.State.Prop:
                    {
                        bool flag = false;
                        if (c == '[')
                        {
                            flag = true;
                        }
                        if (flag)
                        {
                            this.AddIndexer();
                        }
                        else
                        {
                            this.AddProperty();
                        }
                        break;
                    }
                    }
                }
            }
            SourceValueInfo[] array;
            if (this._error == null)
            {
                array = new SourceValueInfo[this._al.Count];
                this._al.CopyTo(array);
            }
            else
            {
                array = PathParser.EmptyInfo;
            }
            return(array);
        }
        // Token: 0x06007627 RID: 30247 RVA: 0x0021AF80 File Offset: 0x00219180
        private void AddIndexer()
        {
            int num = this._index + 1;

            this._index = num;
            int           num2           = num;
            int           num3           = 1;
            bool          flag           = false;
            bool          flag2          = false;
            StringBuilder stringBuilder  = new StringBuilder();
            StringBuilder stringBuilder2 = new StringBuilder();
            FrugalObjectList <IndexerParamInfo> frugalObjectList = new FrugalObjectList <IndexerParamInfo>();

            PathParser.IndexerState indexerState = PathParser.IndexerState.BeginParam;
            while (indexerState != PathParser.IndexerState.Done)
            {
                if (this._index >= this._n)
                {
                    this.SetError("UnmatchedBracket", new object[]
                    {
                        this._path.Substring(num2 - 1)
                    });
                    return;
                }
                string path = this._path;
                num         = this._index;
                this._index = num + 1;
                char c = path[num];
                if (c == '^' && !flag)
                {
                    flag = true;
                }
                else
                {
                    switch (indexerState)
                    {
                    case PathParser.IndexerState.BeginParam:
                        if (flag)
                        {
                            indexerState = PathParser.IndexerState.ValueString;
                            goto IL_108;
                        }
                        if (c == '(')
                        {
                            indexerState = PathParser.IndexerState.ParenString;
                        }
                        else if (!char.IsWhiteSpace(c))
                        {
                            indexerState = PathParser.IndexerState.ValueString;
                            goto IL_108;
                        }
                        break;

                    case PathParser.IndexerState.ParenString:
                        if (flag)
                        {
                            stringBuilder.Append(c);
                        }
                        else if (c == ')')
                        {
                            indexerState = PathParser.IndexerState.ValueString;
                        }
                        else
                        {
                            stringBuilder.Append(c);
                        }
                        break;

                    case PathParser.IndexerState.ValueString:
                        goto IL_108;
                    }
IL_1CC:
                    flag = false;
                    continue;
IL_108:
                    if (flag)
                    {
                        stringBuilder2.Append(c);
                        flag2 = false;
                        goto IL_1CC;
                    }
                    if (num3 > 1)
                    {
                        stringBuilder2.Append(c);
                        flag2 = false;
                        if (c == ']')
                        {
                            num3--;
                            goto IL_1CC;
                        }
                        goto IL_1CC;
                    }
                    else
                    {
                        if (char.IsWhiteSpace(c))
                        {
                            stringBuilder2.Append(c);
                            flag2 = true;
                            goto IL_1CC;
                        }
                        if (c == ',' || c == ']')
                        {
                            string paren = stringBuilder.ToString();
                            string text  = stringBuilder2.ToString();
                            if (flag2)
                            {
                                text = text.TrimEnd(new char[0]);
                            }
                            frugalObjectList.Add(new IndexerParamInfo(paren, text));
                            stringBuilder.Length  = 0;
                            stringBuilder2.Length = 0;
                            flag2        = false;
                            indexerState = ((c == ']') ? PathParser.IndexerState.Done : PathParser.IndexerState.BeginParam);
                            goto IL_1CC;
                        }
                        stringBuilder2.Append(c);
                        flag2 = false;
                        if (c == '[')
                        {
                            num3++;
                            goto IL_1CC;
                        }
                        goto IL_1CC;
                    }
                }
            }
            SourceValueInfo sourceValueInfo = new SourceValueInfo(SourceValueType.Indexer, this._drillIn, frugalObjectList);

            this._al.Add(sourceValueInfo);
            this.StartNewLevel();
        }