|
| 1 | +// <auto-generated /> |
| 2 | +#nullable enable |
| 3 | +using System; |
| 4 | + |
| 5 | +[Flags] |
| 6 | +internal enum TestEnumFormat : byte |
| 7 | +{ |
| 8 | + None = 0, |
| 9 | + Name = 1, |
| 10 | + Value = 2, |
| 11 | + Default = Name | Value |
| 12 | +} |
| 13 | +// <auto-generated /> |
| 14 | +#nullable enable |
| 15 | +using System; |
| 16 | + |
| 17 | +internal static partial class Enums |
| 18 | +{ |
| 19 | + internal static partial class TestEnum |
| 20 | + { |
| 21 | + public const int MemberCount = 2; |
| 22 | + public const bool IsFlagEnum = false; |
| 23 | + |
| 24 | + public static string[] GetMemberNames() => _names ??= new string[] { |
| 25 | + "None", |
| 26 | + "Value" |
| 27 | + }; |
| 28 | + |
| 29 | + public static global::TestEnum[] GetMemberValues() => _values ??= new global::TestEnum[] { |
| 30 | + global::TestEnum.None, |
| 31 | + global::TestEnum.Value |
| 32 | + }; |
| 33 | + |
| 34 | + public static Int32[] GetUnderlyingValues() => _underlyingValues ??= new Int32[] { |
| 35 | + 0, |
| 36 | + 1 |
| 37 | + }; |
| 38 | + |
| 39 | + public static bool TryParse(string value, out global::TestEnum result, TestEnumFormat format = TestEnumFormat.Default, StringComparison comparison = StringComparison.Ordinal) |
| 40 | + { |
| 41 | + if (format.HasFlag(TestEnumFormat.Name)) |
| 42 | + { |
| 43 | + if (value.Equals("None", comparison)) |
| 44 | + { |
| 45 | + result = global::TestEnum.None; |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + if (value.Equals("Value", comparison)) |
| 50 | + { |
| 51 | + result = global::TestEnum.Value; |
| 52 | + return true; |
| 53 | + } |
| 54 | + } |
| 55 | + if (format.HasFlag(TestEnumFormat.Value)) |
| 56 | + { |
| 57 | + if (value.Equals("0", comparison)) |
| 58 | + { |
| 59 | + result = global::TestEnum.None; |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + if (value.Equals("1", comparison)) |
| 64 | + { |
| 65 | + result = global::TestEnum.Value; |
| 66 | + return true; |
| 67 | + } |
| 68 | + } |
| 69 | + result = default; |
| 70 | + return false; |
| 71 | + } |
| 72 | + |
| 73 | +#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER |
| 74 | + public static bool TryParse(ReadOnlySpan<char> value, out global::TestEnum result, TestEnumFormat format = TestEnumFormat.Default, StringComparison comparison = StringComparison.Ordinal) |
| 75 | + { |
| 76 | + if (format.HasFlag(TestEnumFormat.Name)) |
| 77 | + { |
| 78 | + if (value.Equals("None", comparison)) |
| 79 | + { |
| 80 | + result = global::TestEnum.None; |
| 81 | + return true; |
| 82 | + } |
| 83 | + |
| 84 | + if (value.Equals("Value", comparison)) |
| 85 | + { |
| 86 | + result = global::TestEnum.Value; |
| 87 | + return true; |
| 88 | + } |
| 89 | + } |
| 90 | + if (format.HasFlag(TestEnumFormat.Value)) |
| 91 | + { |
| 92 | + if (value.Equals("0", comparison)) |
| 93 | + { |
| 94 | + result = global::TestEnum.None; |
| 95 | + return true; |
| 96 | + } |
| 97 | + |
| 98 | + if (value.Equals("1", comparison)) |
| 99 | + { |
| 100 | + result = global::TestEnum.Value; |
| 101 | + return true; |
| 102 | + } |
| 103 | + } |
| 104 | + result = default; |
| 105 | + return false; |
| 106 | + } |
| 107 | + |
| 108 | + public static global::TestEnum Parse(ReadOnlySpan<char> value, TestEnumFormat format = TestEnumFormat.Default, StringComparison comparison = StringComparison.Ordinal) |
| 109 | + { |
| 110 | + if (!TryParse(value, out global::TestEnum result, format, comparison)) |
| 111 | + throw new ArgumentOutOfRangeException($"Invalid value: {value.ToString()}"); |
| 112 | + |
| 113 | + return result; |
| 114 | + } |
| 115 | +#endif |
| 116 | + |
| 117 | + public static global::TestEnum Parse(string value, TestEnumFormat format = TestEnumFormat.Default, StringComparison comparison = StringComparison.Ordinal) |
| 118 | + { |
| 119 | + if (!TryParse(value, out global::TestEnum result, format, comparison)) |
| 120 | + throw new ArgumentOutOfRangeException($"Invalid value: {value}"); |
| 121 | + |
| 122 | + return result; |
| 123 | + } |
| 124 | + |
| 125 | + public static bool IsDefined(global::TestEnum input) |
| 126 | + { |
| 127 | + Int32[] _isDefinedValues = GetUnderlyingValues(); |
| 128 | + |
| 129 | + for (int i = 0; i < _isDefinedValues.Length; i++) |
| 130 | + { |
| 131 | + if (_isDefinedValues[i] == (Int32)input) |
| 132 | + return true; |
| 133 | + } |
| 134 | + |
| 135 | + return false; |
| 136 | + } |
| 137 | + |
| 138 | + private static string[]? _names; |
| 139 | + private static global::TestEnum[]? _values; |
| 140 | + private static Int32[]? _underlyingValues; |
| 141 | + |
| 142 | + } |
| 143 | +} |
| 144 | +// <auto-generated /> |
| 145 | +#nullable enable |
| 146 | +using System; |
| 147 | +using System.Diagnostics.CodeAnalysis; |
| 148 | + |
| 149 | +internal static partial class TestEnumExtensions |
| 150 | +{ |
| 151 | + public static string GetString(this global::TestEnum value) => value switch |
| 152 | + { |
| 153 | + global::TestEnum.None => "None", |
| 154 | + global::TestEnum.Value => "Value", |
| 155 | + _ => value.ToString() |
| 156 | + }; |
| 157 | + |
| 158 | + public static bool TryGetUnderlyingValue(this global::TestEnum value, out Int32 underlyingValue) |
| 159 | + { |
| 160 | + switch (value) |
| 161 | + { |
| 162 | + case global::TestEnum.None: |
| 163 | + underlyingValue = 0; |
| 164 | + return true; |
| 165 | + case global::TestEnum.Value: |
| 166 | + underlyingValue = 1; |
| 167 | + return true; |
| 168 | + } |
| 169 | + underlyingValue = default; |
| 170 | + return false; |
| 171 | + } |
| 172 | + |
| 173 | + public static Int32 GetUnderlyingValue(this global::TestEnum value) |
| 174 | + { |
| 175 | + if (!TryGetUnderlyingValue(value, out Int32 underlyingValue)) |
| 176 | + throw new ArgumentOutOfRangeException($"Invalid value: {value}"); |
| 177 | + |
| 178 | + return underlyingValue; |
| 179 | + } |
| 180 | +} |
0 commit comments