示例#1
0
        public override AstNode Visit(EventDefinition node)
        {
            // Add the parent static flag.
            if (currentContainer.IsStatic())
            {
                MemberFlags oldInstance = node.GetFlags() & MemberFlags.InstanceMask;
                if (oldInstance == MemberFlags.Static || oldInstance == MemberFlags.Instanced)
                {
                    MemberFlags flags = node.GetFlags() & ~MemberFlags.InstanceMask;
                    node.SetFlags(flags | MemberFlags.Static);
                }
                else
                {
                    Error(node, "static class member cannot {0}.", oldInstance.ToString().ToLower());
                }
            }

            // Link the accessors.
            AstNode acc = node.GetAccessors();

            while (acc != null)
            {
                EventAccessorDefinition eacc = (EventAccessorDefinition)acc;
                string accName = eacc.GetName();
                if (accName == "add")
                {
                    if (node.AddAccessor != null)
                    {
                        Error(node, "an event only can have one add accessor.");
                    }
                    node.AddAccessor = eacc;
                }
                else if (accName == "remove")
                {
                    if (node.RemoveAccessor != null)
                    {
                        Error(node, "an event only can have one remove accessor.");
                    }
                    node.RemoveAccessor = eacc;
                }
                else
                {
                    Error(acc, "invalid event accessor name.");
                }

                acc = acc.GetNext();
            }

            return(node);
        }