本文整理汇总了C#中Enum.AddElement方法的典型用法代码示例。如果您正苦于以下问题:C# Enum.AddElement方法的具体用法?C# Enum.AddElement怎么用?C# Enum.AddElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Enum
的用法示例。
在下文中一共展示了Enum.AddElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseEnumItems
/// <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();
}