Exemplo n.º 1
0
        /// <summary>
        /// Gets the name of the element.
        /// </summary>
        /// <returns>The name of the element.</returns>
        protected override string GetElementName()
        {
            // For an event, the name of the first event declarator is the name of the event.
            EventDeclaratorExpression declarator = this.FindFirstChild <EventDeclaratorExpression>();

            if (declarator != null)
            {
                return(declarator.Identifier.Text);
            }

            throw new SyntaxException(this.Document, this.LineNumber);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses and returns the declarators for an event.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param>
        /// <param name="eventHandlerType">The event type.</param>
        /// <returns>Returns the name of the first event.</returns>
        private string GetEventDeclarators(CodeUnitProxy parentProxy, bool unsafeCode, TypeToken eventHandlerType)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.Ignore(unsafeCode);
            Param.AssertNotNull(eventHandlerType, "eventHandlerType");

            string firstEventName = null;
            Symbol symbol = this.PeekNextSymbol();

            while (symbol.SymbolType != SymbolType.Semicolon && symbol.SymbolType != SymbolType.OpenCurlyBracket)
            {
                this.AdvanceToNextCodeSymbol(parentProxy);
                var declaratorProxy = new CodeUnitProxy(this.document);

                // Get the identifier.
                var identifierExpressionProxy = new CodeUnitProxy(this.document);
                Token identifier = this.GetElementNameToken(identifierExpressionProxy, unsafeCode, true);

                if (firstEventName == null)
                {
                    firstEventName = identifier.Text;
                }

                var identifierExpression = new LiteralExpression(identifierExpressionProxy, identifier);
                declaratorProxy.Children.Add(identifierExpression);

                Expression initialization = null;

                // Check whether there is an equals sign.
                symbol = this.PeekNextSymbol();
                if (symbol.SymbolType == SymbolType.Equals)
                {
                    this.GetOperatorSymbolToken(declaratorProxy, OperatorType.Equals);
                    initialization = this.GetNextExpression(declaratorProxy, ExpressionPrecedence.None, unsafeCode);

                    if (initialization == null)
                    {
                        throw this.CreateSyntaxException();
                    }
                }

                var declaratorExpression = new EventDeclaratorExpression(declaratorProxy, identifierExpression, initialization);

                parentProxy.Children.Add(declaratorExpression);

                // If the next symbol is a comma, continue.
                symbol = this.PeekNextSymbol();
                if (symbol.SymbolType == SymbolType.Comma)
                {
                    this.GetToken(parentProxy, TokenType.Comma, SymbolType.Comma);
                    symbol = this.PeekNextSymbol();
                }
            }

            return firstEventName;
        }