-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathCodeEnum.cs
39 lines (37 loc) · 1.28 KB
/
CodeEnum.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
namespace Kiota.Builder.CodeDOM;
#pragma warning disable CA1711
public class CodeEnum : CodeBlock<BlockDeclaration, BlockEnd>, IDocumentedElement, ITypeDefinition, IDeprecableElement
{
#pragma warning restore CA2227
public bool Flags
{
get; set;
}
public CodeDocumentation Documentation { get; set; } = new();
private readonly ConcurrentQueue<CodeEnumOption> OptionsInternal = new(); // this structure is used to maintain the order of the options
public void AddOption(params CodeEnumOption[] codeEnumOptions)
{
if (codeEnumOptions is null) return;
var result = AddRange(codeEnumOptions);
foreach (var option in result.Distinct())
{
OptionsInternal.Enqueue(option);
}
}
public IEnumerable<CodeEnumOption> Options
{
get
{
return OptionsInternal.Join(InnerChildElements.Values.OfType<CodeEnumOption>().ToHashSet(), static x => x, static y => y, static (x, y) => x);
// maintaining order of the options is important for enums as they are often used with comparisons
}
}
public DeprecationInformation? Deprecation
{
get; set;
}
}