Я пытаюсь добавить выбор «NoneOfTheBelow» ко всем перечислениям, проанализированным из файла XSD. Я расширяю код из инструмента Xsd2Code.
Когда я генерирую вывод, используя приведенный ниже код, перечисление не содержит нового добавленного элемента. Кто-нибудь может помочь?
var ns = new CodeNamespace();
/* ... Initialize ns from XSD ... */
// Create a dummy array for iteration, because a collection cannot be modified when it is being iterated over.
CodeTypeDeclarationCollection types = new CodeTypeDeclarationCollection();
foreach (CodeTypeDeclaration t0 in ns.Types)
{
types.Add(new CodeTypeDeclaration(t0.Name));
}
// Scan for enum types and add desired markup to the members.
int typeIndex = 0;
foreach (CodeTypeDeclaration t0 in types)
{
CodeTypeDeclaration t = ns.Types[typeIndex];
// Add an element for blank entry to the enum.
CodeTypeMember noneOfTheBelow = new CodeTypeMember();
noneOfTheBelow.Name = "NoneOfTheBelow";
noneOfTheBelow.Comments.Add(new CodeCommentStatement( "<summary>None of the below.</summary>"));
noneOfTheBelow.CustomAttributes.Add(new CodeAttributeDeclaration("XmlEnum", new CodeAttributeArgument(new CodePrimitiveExpression("Test"))));
noneOfTheBelow.CustomAttributes.Add(new CodeAttributeDeclaration("Description", new CodeAttributeArgument(new CodePrimitiveExpression("Test"))));
t.Members.Insert(0, noneOfTheBelow);
}