You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/EnumSourceGeneratorTests.cs
+226Lines changed: 226 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -741,6 +741,232 @@ public partial class TestEnum : IEnum<string>
= new global::System.Lazy<global::System.Collections.Generic.IReadOnlyDictionary<string, global::Thinktecture.Tests.TestEnum>>(GetLookup, global::System.Threading.LazyThreadSafetyMode.PublicationOnly);
public static global::Thinktecture.Tests.TestEnum? Get(string? key)
848
+
{
849
+
if (key is null)
850
+
return default;
851
+
852
+
if (!_itemsLookup.Value.TryGetValue(key, out var item))
853
+
{
854
+
throw new global::Thinktecture.UnknownEnumIdentifierException(typeof(global::Thinktecture.Tests.TestEnum), key);
855
+
}
856
+
857
+
return item;
858
+
}
859
+
860
+
/// <summary>
861
+
/// Gets a valid enumeration item for provided <paramref name="key"/> if a valid item exists.
862
+
/// </summary>
863
+
/// <param name="key">The identifier to return an enumeration item for.</param>
864
+
/// <param name="item">A valid instance of <see cref="TestEnum"/>; otherwise <c>null</c>.</param>
865
+
/// <returns><c>true</c> if a valid item with provided <paramref name="key"/> exists; <c>false</c> otherwise.</returns>
866
+
public static bool TryGet([global::System.Diagnostics.CodeAnalysis.AllowNull] string key, [global::System.Diagnostics.CodeAnalysis.MaybeNullWhen(false)] out global::Thinktecture.Tests.TestEnum item)
867
+
{
868
+
if (key is null)
869
+
{
870
+
item = default;
871
+
return false;
872
+
}
873
+
874
+
return _itemsLookup.Value.TryGetValue(key, out item);
875
+
}
876
+
877
+
/// <summary>
878
+
/// Validates the provided <paramref name="key"/> and returns a valid enumeration item if found.
879
+
/// </summary>
880
+
/// <param name="key">The identifier to return an enumeration item for.</param>
881
+
/// <param name="item">A valid instance of <see cref="TestEnum"/>; otherwise <c>null</c>.</param>
882
+
/// <returns> <see cref="System.ComponentModel.DataAnnotations.ValidationResult.Success"/> if a valid item with provided <paramref name="key"/> exists; <see cref="System.ComponentModel.DataAnnotations.ValidationResult"/> with an error message otherwise.</returns>
883
+
public static global::System.ComponentModel.DataAnnotations.ValidationResult? Validate([global::System.Diagnostics.CodeAnalysis.AllowNull] string key, [global::System.Diagnostics.CodeAnalysis.MaybeNull] out global::Thinktecture.Tests.TestEnum item)
884
+
{
885
+
if(global::Thinktecture.Tests.TestEnum.TryGet(key, out item))
return new global::System.ComponentModel.DataAnnotations.ValidationResult($"There is no item of type 'TestEnum' with the identifier '{key}'.", global::Thinktecture.SingleItem.Collection(nameof(global::Thinktecture.Tests.TestEnum.Key)));
892
+
}
893
+
}
894
+
895
+
/// <summary>
896
+
/// Implicit conversion to the type <see cref="string"/>.
897
+
/// </summary>
898
+
/// <param name="item">Item to covert.</param>
899
+
/// <returns>The <see cref="TestEnum.Key"/> of provided <paramref name="item"/> or <c>default</c> if <paramref name="item"/> is <c>null</c>.</returns>
public static implicit operator string?(global::Thinktecture.Tests.TestEnum? item)
902
+
{
903
+
return item is null ? default : item.Key;
904
+
}
905
+
906
+
/// <summary>
907
+
/// Explicit conversion from the type <see cref="string"/>.
908
+
/// </summary>
909
+
/// <param name="key">Value to covert.</param>
910
+
/// <returns>An instance of <see cref="TestEnum"/> if the <paramref name="key"/> is a known item or implements <see cref="Thinktecture.IValidatableEnum{TKey}"/>.</returns>
0 commit comments