/// <summary> /// Parses and returns the items within an enum element. /// </summary> /// <param name="parent">The parent enum element.</param> /// <param name="parentReference">Reference to the parent of the items we're creating.</param> /// <param name="unsafeCode">Indicates whether the code is marked as unsafe.</param> /// <returns>Returns the element.</returns> private ICollection<EnumItem> ParseEnumItems(Enum parent, Reference<ICodePart> parentReference, bool unsafeCode) { Param.AssertNotNull(parent, "parent"); Param.Ignore(unsafeCode); Param.AssertNotNull(parentReference, "parentReference"); List<EnumItem> enumItems = new List<EnumItem>(); SkipSymbols skip = SkipSymbols.All; skip &= ~SkipSymbols.XmlHeader; Symbol symbol = this.GetNextSymbol(skip, parentReference); while (symbol.SymbolType != SymbolType.CloseCurlyBracket) { // Get the enum header. XmlHeader xmlHeader = null; ICollection<Attribute> attributes; var enumItemReference = new Reference<ICodePart>(); this.MoveToElementDeclaration(parentReference, enumItemReference, unsafeCode, out xmlHeader, out attributes); // If the next symbol is a close curly bracket, quit. symbol = this.GetNextSymbol(enumItemReference); if (symbol.SymbolType == SymbolType.CloseCurlyBracket) { break; } // Get the enum item name. Node<CsToken> firstEnumItemToken = this.tokens.InsertLast(this.GetToken(CsTokenType.Other, SymbolType.Other, enumItemReference)); Expression initializationExpression = null; // See if there is an equals sign. symbol = this.GetNextSymbol(enumItemReference); if (symbol.SymbolType == SymbolType.Equals) { this.tokens.Add(this.GetOperatorToken(OperatorType.Equals, enumItemReference)); // Get the constant expression being assigned. initializationExpression = this.GetNextExpression(ExpressionPrecedence.None, enumItemReference, unsafeCode); } CsTokenList enumItemTokens = new CsTokenList(this.tokens, firstEnumItemToken, this.tokens.Last); Declaration enumItemDeclaration = new Declaration( enumItemTokens, firstEnumItemToken.Value.Text, ElementType.EnumItem, AccessModifierType.Public); EnumItem enumItem = new EnumItem( this.document, parent, xmlHeader, attributes, enumItemDeclaration, initializationExpression, unsafeCode, this.symbols.Generated); enumItemReference.Target = enumItem; enumItem.Tokens = new CsTokenList(this.tokens, firstEnumItemToken, this.tokens.Last); enumItems.Add(enumItem); parent.AddElement(enumItem); symbol = this.GetNextSymbol(parentReference); // If the symbol is not a comma, quit. if (symbol.SymbolType == SymbolType.Comma) { this.tokens.Add(this.GetToken(CsTokenType.Comma, SymbolType.Comma, parentReference)); } else { break; } symbol = this.GetNextSymbol(skip, parentReference); } // Return the enum items as a read-only collection. return enumItems.ToArray(); }