// Token: 0x060021C4 RID: 8644 RVA: 0x000A8FD8 File Offset: 0x000A71D8
        private SpecialBracketCharacters GetBracketCharacterForProperty(string propertyName, Dictionary <string, SpecialBracketCharacters> bracketCharacterCache)
        {
            SpecialBracketCharacters result = null;

            if (bracketCharacterCache != null && bracketCharacterCache.ContainsKey(propertyName))
            {
                result = bracketCharacterCache[propertyName];
            }
            return(result);
        }
예제 #2
0
        object _rootElement;                                       // RootElement for the Page scoping [temporary, should be
                                                                   // something like page name or baseUri]
#endif

        /// <summary>
        /// Looks up all properties via reflection on the given type, and scans through the attributes on all of them
        /// to build a cache of properties which have MarkupExtensionBracketCharactersAttribute set on them.
        /// </summary>
        private Dictionary <string, SpecialBracketCharacters> BuildBracketCharacterCacheForType(Type extensionType)
        {
            Dictionary <string, SpecialBracketCharacters> cache = new Dictionary <string, SpecialBracketCharacters>(StringComparer.OrdinalIgnoreCase);

            PropertyInfo[] propertyInfo                        = extensionType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            Type           constructorArgumentType             = null;
            Type           markupExtensionBracketCharacterType = null;

            foreach (PropertyInfo property in propertyInfo)
            {
                string propertyName            = property.Name;
                string constructorArgumentName = null;
                IList <CustomAttributeData> customAttributes  = CustomAttributeData.GetCustomAttributes(property);
                SpecialBracketCharacters    bracketCharacters = null;
                foreach (CustomAttributeData attributeData in customAttributes)
                {
                    Type     attributeType = attributeData.AttributeType;
                    Assembly xamlAssembly  = attributeType.Assembly;
                    if (constructorArgumentType == null || markupExtensionBracketCharacterType == null)
                    {
                        constructorArgumentType =
                            xamlAssembly.GetType("System.Windows.Markup.ConstructorArgumentAttribute");
                        markupExtensionBracketCharacterType =
                            xamlAssembly.GetType("System.Windows.Markup.MarkupExtensionBracketCharactersAttribute");
                    }

                    if (attributeType.IsAssignableFrom(constructorArgumentType))
                    {
                        constructorArgumentName = attributeData.ConstructorArguments[0].Value as string;
                    }
                    else if (attributeType.IsAssignableFrom(markupExtensionBracketCharacterType))
                    {
                        if (bracketCharacters == null)
                        {
                            bracketCharacters = new SpecialBracketCharacters();
                        }

                        bracketCharacters.AddBracketCharacters((char)attributeData.ConstructorArguments[0].Value, (char)attributeData.ConstructorArguments[1].Value);
                    }
                }

                if (bracketCharacters != null)
                {
                    bracketCharacters.EndInit();
                    cache.Add(propertyName, bracketCharacters);
                    if (constructorArgumentName != null)
                    {
                        cache.Add(constructorArgumentName, bracketCharacters);
                    }
                }
            }

            return(cache.Count == 0 ? null : cache);
        }
예제 #3
0
 public MeScanner(XamlParserContext context, string text, int lineNumber, int linePosition)
 {
     _context                         = context;
     _inputText                       = text;
     _lineNumber                      = lineNumber;
     _startPosition                   = linePosition;
     _idx                             = -1;
     _state                           = StringState.Value;
     _currentParameterName            = null;
     _currentSpecialBracketCharacters = null;
 }
예제 #4
0
        // Token: 0x06002201 RID: 8705 RVA: 0x000A9E78 File Offset: 0x000A8078
        private Dictionary <string, SpecialBracketCharacters> BuildBracketCharacterCacheForType(Type extensionType)
        {
            Dictionary <string, SpecialBracketCharacters> dictionary = new Dictionary <string, SpecialBracketCharacters>(StringComparer.OrdinalIgnoreCase);

            PropertyInfo[] properties = extensionType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
            Type           type       = null;
            Type           type2      = null;

            foreach (PropertyInfo propertyInfo in properties)
            {
                string name = propertyInfo.Name;
                string text = null;
                IList <CustomAttributeData> customAttributes         = CustomAttributeData.GetCustomAttributes(propertyInfo);
                SpecialBracketCharacters    specialBracketCharacters = null;
                foreach (CustomAttributeData customAttributeData in customAttributes)
                {
                    Type     attributeType = customAttributeData.AttributeType;
                    Assembly assembly      = attributeType.Assembly;
                    if (type == null || type2 == null)
                    {
                        type  = assembly.GetType("System.Windows.Markup.ConstructorArgumentAttribute");
                        type2 = assembly.GetType("System.Windows.Markup.MarkupExtensionBracketCharactersAttribute");
                    }
                    if (attributeType.IsAssignableFrom(type))
                    {
                        text = (customAttributeData.ConstructorArguments[0].Value as string);
                    }
                    else if (attributeType.IsAssignableFrom(type2))
                    {
                        if (specialBracketCharacters == null)
                        {
                            specialBracketCharacters = new SpecialBracketCharacters();
                        }
                        specialBracketCharacters.AddBracketCharacters((char)customAttributeData.ConstructorArguments[0].Value, (char)customAttributeData.ConstructorArguments[1].Value);
                    }
                }
                if (specialBracketCharacters != null)
                {
                    specialBracketCharacters.EndInit();
                    dictionary.Add(name, specialBracketCharacters);
                    if (text != null)
                    {
                        dictionary.Add(text, specialBracketCharacters);
                    }
                }
            }
            if (dictionary.Count != 0)
            {
                return(dictionary);
            }
            return(null);
        }
예제 #5
0
        private string ReadString()
        {
            bool escaped    = false;
            char quoteChar  = NullChar;
            bool atStart    = true;
            bool wasQuoted  = false;
            uint braceCount = 0;    // To be compat with v3 which allowed balanced {} inside of strings

            StringBuilder sb = new StringBuilder();
            char          ch;

            while (!IsAtEndOfInput)
            {
                ch = CurrentChar;

                // handle escaping and quoting first.
                if (escaped)
                {
                    sb.Append('\\');
                    sb.Append(ch);
                    escaped = false;
                }
                else if (quoteChar != NullChar)
                {
                    if (ch == Backslash)
                    {
                        escaped = true;
                    }
                    else if (ch != quoteChar)
                    {
                        sb.Append(ch);
                    }
                    else
                    {
                        ch        = CurrentChar;
                        quoteChar = NullChar;
                        break;  // we are done.
                    }
                }
                // If we are inside of MarkupExtensionBracketCharacters for a particular property or position parameter,
                // scoop up everything inside one by one, and keep track of nested Bracket Characters in the stack.
                else if (_context.CurrentBracketModeParseParameters != null && _context.CurrentBracketModeParseParameters.IsBracketEscapeMode)
                {
                    Stack <char> bracketCharacterStack = _context.CurrentBracketModeParseParameters.BracketCharacterStack;
                    if (_currentSpecialBracketCharacters.StartsEscapeSequence(ch))
                    {
                        bracketCharacterStack.Push(ch);
                    }
                    else if (_currentSpecialBracketCharacters.EndsEscapeSequence(ch))
                    {
                        if (_currentSpecialBracketCharacters.Match(bracketCharacterStack.Peek(), ch))
                        {
                            bracketCharacterStack.Pop();
                        }
                        else
                        {
                            throw new XamlParseException(this, SR.Get(SRID.InvalidClosingBracketCharacers, ch.ToString()));
                        }
                    }
                    else if (ch == Backslash)
                    {
                        escaped = true;
                    }

                    if (bracketCharacterStack.Count == 0)
                    {
                        _context.CurrentBracketModeParseParameters.IsBracketEscapeMode = false;
                    }

                    if (!escaped)
                    {
                        sb.Append(ch);
                    }
                }
                else
                {
                    bool done = false;
                    switch (ch)
                    {
                    case Space:
                        if (_state == StringState.Type)
                        {
                            done = true;  // we are done.
                            break;
                        }
                        sb.Append(ch);
                        break;

                    case OpenCurlie:
                        braceCount++;
                        sb.Append(ch);
                        break;

                    case CloseCurlie:
                        if (braceCount == 0)
                        {
                            done = true;
                        }
                        else
                        {
                            braceCount--;
                            sb.Append(ch);
                        }
                        break;

                    case Comma:
                        done = true;  // we are done.
                        break;

                    case EqualSign:
                        _state = StringState.Property;
                        done   = true; // we are done.
                        break;

                    case Backslash:
                        escaped = true;
                        break;

                    case Quote1:
                    case Quote2:
                        if (!atStart)
                        {
                            throw new XamlParseException(this, SR.Get(SRID.QuoteCharactersOutOfPlace));
                        }
                        quoteChar = ch;
                        wasQuoted = true;
                        break;

                    default:  // All other character (including whitespace)
                        if (_currentSpecialBracketCharacters != null && _currentSpecialBracketCharacters.StartsEscapeSequence(ch))
                        {
                            Stack <char> bracketCharacterStack =
                                _context.CurrentBracketModeParseParameters.BracketCharacterStack;
                            bracketCharacterStack.Clear();
                            bracketCharacterStack.Push(ch);
                            _context.CurrentBracketModeParseParameters.IsBracketEscapeMode = true;
                        }

                        sb.Append(ch);
                        break;
                    }

                    if (done)
                    {
                        if (braceCount > 0)
                        {
                            throw new XamlParseException(this, SR.Get(SRID.UnexpectedTokenAfterME));
                        }
                        else
                        {
                            if (_context.CurrentBracketModeParseParameters?.BracketCharacterStack.Count > 0)
                            {
                                throw new XamlParseException(this, SR.Get(SRID.MalformedBracketCharacters, ch.ToString()));
                            }
                        }

                        PushBack();
                        break;  // we are done.
                    }
                }
                atStart = false;
                Advance();
            }

            if (quoteChar != NullChar)
            {
                throw new XamlParseException(this, SR.Get(SRID.UnclosedQuote));
            }

            string result = sb.ToString();

            if (!wasQuoted)
            {
                result = result.TrimEnd(KnownStrings.WhitespaceChars);
                result = result.TrimStart(KnownStrings.WhitespaceChars);
            }

            if (_state == StringState.Property)
            {
                _currentParameterName            = result;
                _currentSpecialBracketCharacters = GetBracketCharacterForProperty(_currentParameterName);
            }

            return(result);
        }
예제 #6
0
        public void Read()
        {
            bool isQuotedMarkupExtension = false;
            bool readString = false;

            _tokenText      = string.Empty;
            _tokenXamlType  = null;
            _tokenProperty  = null;
            _tokenNamespace = null;

            Advance();
            AdvanceOverWhitespace();

            if (IsAtEndOfInput)
            {
                _token = MeTokenType.None;
                return;
            }

            switch (CurrentChar)
            {
            case OpenCurlie:
                if (NextChar == CloseCurlie)    // the {} escapes the ME.  return the string.
                {
                    _token     = MeTokenType.String;
                    _state     = StringState.Value;
                    readString = true;          // ReadString() will strip the leading {}
                }
                else
                {
                    _token = MeTokenType.Open;
                    _state = StringState.Type;  // types follow '{'
                }
                break;

            case Quote1:
            case Quote2:
                if (NextChar == OpenCurlie)
                {
                    Advance();                    // read ahead one character
                    if (NextChar != CloseCurlie)  // check for the '}' of a {}
                    {
                        isQuotedMarkupExtension = true;
                    }
                    PushBack();     // put back the read-ahead.
                }
                readString = true;  // read substring"
                break;

            case CloseCurlie:
                _token = MeTokenType.Close;
                _state = StringState.Value;
                break;

            case EqualSign:
                _token = MeTokenType.EqualSign;
                _state = StringState.Value;
                _context.CurrentBracketModeParseParameters.IsConstructorParsingMode = false;
                break;

            case Comma:
                _token = MeTokenType.Comma;
                _state = StringState.Value;
                if (_context.CurrentBracketModeParseParameters.IsConstructorParsingMode)
                {
                    _context.CurrentBracketModeParseParameters.IsConstructorParsingMode =
                        ++_context.CurrentBracketModeParseParameters.CurrentConstructorParam <
                        _context.CurrentBracketModeParseParameters.MaxConstructorParams;
                }
                break;

            default:
                readString = true;
                break;
            }

            if (readString)
            {
                if (_context.CurrentType.IsMarkupExtension &&
                    _context.CurrentBracketModeParseParameters != null &&
                    _context.CurrentBracketModeParseParameters.IsConstructorParsingMode)
                {
                    int currentCtrParam = _context.CurrentBracketModeParseParameters.CurrentConstructorParam;
                    //_currentParameterName = _context.CurrentLongestConstructorOfMarkupExtension[currentCtrParam].Name;
                    _currentSpecialBracketCharacters = GetBracketCharacterForProperty(_currentParameterName);
                }

                string str = ReadString();
                _token = (isQuotedMarkupExtension) ? MeTokenType.QuotedMarkupExtension : MeTokenType.String;

                switch (_state)
                {
                case StringState.Value:
                    break;

                case StringState.Type:
                    _token = MeTokenType.TypeName;
                    ResolveTypeName(str);
                    break;

                case StringState.Property:
                    _token = MeTokenType.PropertyName;
                    ResolvePropertyName(str);
                    break;
                }
                _state     = StringState.Value;
                _tokenText = RemoveEscapes(str);
            }
        }
        // Token: 0x060021BE RID: 8638 RVA: 0x000A86EC File Offset: 0x000A68EC
        private ArrayList TokenizeAttributes(string args, int lineNumber, int linePosition, Type extensionType)
        {
            if (extensionType == typeof(MarkupExtensionParser.UnknownMarkupExtension))
            {
                return(null);
            }
            int num = 0;

            ParameterInfo[] array = this.FindLongestConstructor(extensionType, out num);
            Dictionary <string, SpecialBracketCharacters> dictionary = this._parserContext.InitBracketCharacterCacheForType(extensionType);
            Stack <char>             stack                    = new Stack <char>();
            int                      num2                     = 0;
            bool                     flag                     = array != null && num > 0;
            bool                     flag2                    = false;
            ArrayList                arrayList                = null;
            int                      length                   = args.Length;
            bool                     flag3                    = false;
            bool                     flag4                    = false;
            bool                     flag5                    = false;
            bool                     flag6                    = false;
            char                     c                        = '\'';
            int                      num3                     = 0;
            StringBuilder            stringBuilder            = null;
            SpecialBracketCharacters specialBracketCharacters = null;

            if (flag && dictionary != null)
            {
                string text = (num > 0) ? array[num2].Name : null;
                if (!string.IsNullOrEmpty(text))
                {
                    specialBracketCharacters = this.GetBracketCharacterForProperty(text, dictionary);
                }
            }
            int num4 = 0;

            while (num4 < length && !flag6)
            {
                if (!flag4 && args[num4] == '\\')
                {
                    flag4 = true;
                }
                else
                {
                    if (!flag5 && !char.IsWhiteSpace(args[num4]))
                    {
                        flag5 = true;
                    }
                    if (flag3 || num3 > 0 || flag5)
                    {
                        if (stringBuilder == null)
                        {
                            stringBuilder = new StringBuilder(length);
                            arrayList     = new ArrayList(1);
                        }
                        if (flag4)
                        {
                            stringBuilder.Append('\\');
                            stringBuilder.Append(args[num4]);
                            flag4 = false;
                        }
                        else if (flag3 || num3 > 0)
                        {
                            if (flag3 && args[num4] == c)
                            {
                                flag3 = false;
                                flag5 = false;
                                MarkupExtensionParser.AddToTokenList(arrayList, stringBuilder, false);
                            }
                            else
                            {
                                if (num3 > 0 && args[num4] == '}')
                                {
                                    num3--;
                                }
                                else if (args[num4] == '{')
                                {
                                    num3++;
                                }
                                stringBuilder.Append(args[num4]);
                            }
                        }
                        else if (flag2)
                        {
                            stringBuilder.Append(args[num4]);
                            if (specialBracketCharacters.StartsEscapeSequence(args[num4]))
                            {
                                stack.Push(args[num4]);
                            }
                            else if (specialBracketCharacters.EndsEscapeSequence(args[num4]))
                            {
                                if (specialBracketCharacters.Match(stack.Peek(), args[num4]))
                                {
                                    stack.Pop();
                                }
                                else
                                {
                                    this.ThrowException("ParserMarkupExtensionInvalidClosingBracketCharacers", args[num4].ToString(), lineNumber, linePosition);
                                }
                            }
                            if (stack.Count == 0)
                            {
                                flag2 = false;
                            }
                        }
                        else
                        {
                            char c2 = args[num4];
                            if (c2 <= ',')
                            {
                                if (c2 == '"' || c2 == '\'')
                                {
                                    if (stringBuilder.Length != 0)
                                    {
                                        this.ThrowException("ParserMarkupExtensionNoQuotesInName", args, lineNumber, linePosition);
                                    }
                                    flag3 = true;
                                    c     = args[num4];
                                    goto IL_441;
                                }
                                if (c2 != ',')
                                {
                                    goto IL_405;
                                }
                            }
                            else if (c2 != '=')
                            {
                                if (c2 == '{')
                                {
                                    num3++;
                                    stringBuilder.Append(args[num4]);
                                    goto IL_441;
                                }
                                if (c2 != '}')
                                {
                                    goto IL_405;
                                }
                                flag6 = true;
                                if (stringBuilder == null)
                                {
                                    goto IL_441;
                                }
                                if (stringBuilder.Length > 0)
                                {
                                    MarkupExtensionParser.AddToTokenList(arrayList, stringBuilder, true);
                                    goto IL_441;
                                }
                                if (arrayList.Count > 0 && arrayList[arrayList.Count - 1] is char)
                                {
                                    this.ThrowException("ParserMarkupExtensionBadDelimiter", args, lineNumber, linePosition);
                                    goto IL_441;
                                }
                                goto IL_441;
                            }
                            if (flag && args[num4] == ',')
                            {
                                flag = (++num2 < num);
                                if (flag)
                                {
                                    string text = array[num2].Name;
                                    specialBracketCharacters = this.GetBracketCharacterForProperty(text, dictionary);
                                }
                            }
                            if (stringBuilder != null && stringBuilder.Length > 0)
                            {
                                MarkupExtensionParser.AddToTokenList(arrayList, stringBuilder, true);
                                if (stack.Count != 0)
                                {
                                    this.ThrowException("ParserMarkupExtensionMalformedBracketCharacers", stack.Peek().ToString(), lineNumber, linePosition);
                                }
                            }
                            else if (arrayList.Count == 0)
                            {
                                this.ThrowException("ParserMarkupExtensionDelimiterBeforeFirstAttribute", args, lineNumber, linePosition);
                            }
                            else if (arrayList[arrayList.Count - 1] is char)
                            {
                                this.ThrowException("ParserMarkupExtensionBadDelimiter", args, lineNumber, linePosition);
                            }
                            if (args[num4] == '=')
                            {
                                flag = false;
                                string text = (string)arrayList[arrayList.Count - 1];
                                specialBracketCharacters = this.GetBracketCharacterForProperty(text, dictionary);
                            }
                            arrayList.Add(args[num4]);
                            flag5 = false;
                            goto IL_441;
IL_405:
                            if (specialBracketCharacters != null && specialBracketCharacters.StartsEscapeSequence(args[num4]))
                            {
                                stack.Clear();
                                stack.Push(args[num4]);
                                flag2 = true;
                            }
                            stringBuilder.Append(args[num4]);
                        }
                    }
                }
IL_441:
                num4++;
            }
            if (!flag6)
            {
                this.ThrowException("ParserMarkupExtensionNoEndCurlie", "}", lineNumber, linePosition);
            }
            else if (num4 < length)
            {
                this.ThrowException("ParserMarkupExtensionTrailingGarbage", "}", args.Substring(num4, length - num4), lineNumber, linePosition);
            }
            return(arrayList);
        }