Event element.
Inheritance: InterfaceMemberElement
Beispiel #1
0
        /// <summary>
        /// Parses an event.
        /// </summary>
        /// <param name="access">The event access.</param>
        /// <param name="memberAttributes">The member attributes.</param>
        /// <param name="isCustom">Whether or not the event is custom.</param>
        /// <returns>An event code element.</returns>
        private EventElement ParseEvent(
            CodeAccess access, MemberModifiers memberAttributes, bool isCustom)
        {
            EventElement eventElement = new EventElement();
            string name = CaptureWord();
            eventElement.Name = name;
            eventElement.Access = access;
            eventElement.MemberModifiers = memberAttributes;

            EatWhiteSpace(WhiteSpaceTypes.SpaceAndTab);
            if (NextChar == VBSymbol.BeginParameterList)
            {
                eventElement.Parameters = ParseNestedText(
                    VBSymbol.BeginParameterList, VBSymbol.EndParameterList, true, true);
            }
            else
            {
                EatWord(VBKeyword.As);

                string eventType = CaptureTypeName();
                if (string.IsNullOrEmpty(eventType))
                {
                    this.OnParseError("Expected type identifier");
                }
                eventElement.Type = eventType;
            }

            string[] implements;
            string blockTemp = TryParseImplements(out implements);
            foreach (string implementation in implements)
            {
                InterfaceReference interfaceReference =
                    new InterfaceReference(implementation, InterfaceReferenceType.Interface);
                eventElement.AddImplementation(interfaceReference);
            }

            if (isCustom)
            {
                eventElement.BodyText = (blockTemp + this.ParseBlock(VBKeyword.Event)).Trim();
            }

            return eventElement;
        }
Beispiel #2
0
 /// <summary>
 /// Processes a event element.
 /// </summary>
 /// <param name="element">Event code element.</param>
 public abstract void VisitEventElement(EventElement element);
        /// <summary>
        /// Processes an event element.
        /// </summary>
        /// <param name="element">Event code element.</param>
        public override void VisitEventElement(EventElement element)
        {
            this.WriteComments(element.HeaderComments);
            this.WriteAttributes(element);

            WriteAccess(element.Access);

            WriteMemberAttributes(element.MemberModifiers);

            Writer.Write(CSharpKeyword.Event);
            Writer.Write(' ');

            Writer.Write(element.Type);
            Writer.Write(' ');

            Writer.Write(element.Name);

            if (element.BodyText != null && element.BodyText.Length > 0)
            {
                Writer.WriteLine();
                WriteBody(element);
            }
            else
            {
                Writer.Write(CSharpSymbol.EndOfStatement);
            }
        }
        /// <summary>
        /// Processes an event element.
        /// </summary>
        /// <param name="element">Event code element.</param>
        public override void VisitEventElement(EventElement element)
        {
            this.WriteComments(element.HeaderComments);
            this.WriteAttributes(element);

            WriteAccess(element.Access);

            WriteMemberAttributes(
                element.MemberModifiers,
                element[VBExtendedProperties.Overloads] is bool && (bool)element[VBExtendedProperties.Overloads]);

            bool isCustom = false;
            if (element.BodyText != null && element.BodyText.Trim().Length > 0)
            {
                isCustom = true;
                Writer.Write(VBKeyword.Custom);
                Writer.Write(' ');
            }

            Writer.Write(VBKeyword.Event);
            Writer.Write(' ');

            Writer.Write(element.Name);

            if (element.Parameters != null)
            {
                WriteParameterList(element.Parameters);
            }
            WriteReturnType(element.Type);
            WriteImplements(element.Implements);

            if (isCustom)
            {
                WriteBody(element);
            }
        }
        /// <summary>
        /// Parses an event.
        /// </summary>
        /// <param name="access">Member accessibility.</param>
        /// <param name="memberAttributes">Member modifiers.</param>
        /// <returns>Event code element.</returns>
        private EventElement ParseEvent(CodeAccess access, MemberModifiers memberAttributes)
        {
            EventElement eventElement = new EventElement();

            StringBuilder eventSignature = new StringBuilder();
            while (NextChar != CSharpSymbol.EndOfStatement &&
                NextChar != CSharpSymbol.BeginBlock)
            {
                if (TryReadChar())
                {
                    eventSignature.Append(CurrentChar);
                }
            }

            string[] words = eventSignature.ToString().Split(WhiteSpaceCharacters, StringSplitOptions.RemoveEmptyEntries);
            StringCollection wordList = new StringCollection();
            wordList.AddRange(words);
            string name = null;
            string type = null;

            GetMemberNameAndType(wordList, out name, out type);

            eventElement.Type = type;
            eventElement.Name = name;
            eventElement.Access = access;
            eventElement.MemberModifiers = memberAttributes;

            EatWhiteSpace();

            char nextChar = NextChar;
            if (nextChar == CSharpSymbol.EndOfStatement)
            {
                EatChar(CSharpSymbol.EndOfStatement);
            }
            else
            {
                eventElement.BodyText = this.ParseBlock(true, eventElement);
            }

            return eventElement;
        }