Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Enum.GetValues<T> instead of Enum.GetValues in numerous places for .NET. #18382

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions msbuild/Xamarin.MacDev.Tasks/TargetArchitecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public static IList<TargetArchitecture> ToArray (this TargetArchitecture self)

var rv = new List<TargetArchitecture> ();

#if NET
var simpleValues = new List<TargetArchitecture> (Enum.GetValues<TargetArchitecture> ());
#else
var simpleValues = new List<TargetArchitecture> ((TargetArchitecture []) Enum.GetValues (typeof (TargetArchitecture)));
#endif
simpleValues.Remove (TargetArchitecture.Default);
simpleValues.Remove (TargetArchitecture.ARMv6_ARMv7);

Expand Down
4 changes: 4 additions & 0 deletions src/Contacts/CNContact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public bool AreKeysAvailable<T> (T [] keyDescriptors)
public bool AreKeysAvailable (CNContactOptions options)
{
using (var array = new NSMutableArray ()) {
#if NET
foreach (var value in Enum.GetValues<CNContactOptions> ()) {
#else
foreach (CNContactOptions value in Enum.GetValues (typeof (CNContactOptions))) {
#endif
if ((options & value) != CNContactOptions.None)
array.Add (ContactOptionsToNSString (value));
}
Expand Down
4 changes: 4 additions & 0 deletions src/PassKit/PKPaymentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ static public NSSet GetSet (PKContactFields values)
if (values == PKContactFields.None)
return set;

#if NET
foreach (var value in Enum.GetValues<PKContactFields> ()) {
#else
foreach (PKContactFields value in Enum.GetValues (typeof (PKContactFields))) {
#endif
if (values.HasFlag (value)) {
var constant = value.GetConstant ();
// None does not have an associated native value and Contains would throw an ANE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ public void MetadataObjectTypesTest ()
captureSession.AddOutput (metadataOutput);

AVMetadataObjectType all = AVMetadataObjectType.None;
#if NET
foreach (var val in Enum.GetValues<AVMetadataObjectType> ()) {
#else
foreach (AVMetadataObjectType val in Enum.GetValues (typeof (AVMetadataObjectType))) {
#endif
switch (val) {
case AVMetadataObjectType.CatBody:
case AVMetadataObjectType.DogBody:
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/CoreImage/CIKernelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ public void CIKernel_BasicTest ()
#endif


#if NET
foreach (var type in Enum.GetValues<CustomerFilterType> ()) {
#else
foreach (CustomerFilterType type in Enum.GetValues (typeof (CustomerFilterType))) {
#endif
MyCustomFilter filter = new MyCustomFilter (type);
filter.MyImage = ciImg;

Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/Foundation/CalendarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ public void GetAllCalendarIdentifiers ()
{
RequiresIos8 ();

#if NET
foreach (var t in Enum.GetValues<NSCalendarType> ()) {
#else
foreach (NSCalendarType t in Enum.GetValues (typeof (NSCalendarType))) {
#endif
switch (t) {
case NSCalendarType.IslamicTabular:
case NSCalendarType.IslamicUmmAlQura:
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/HealthKit/CategoryTypeIdentifierTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public void EnumValues_22351 ()

var failures = new List<string> ();

#if NET
foreach (var value in Enum.GetValues<HKCategoryTypeIdentifier> ()) {
#else
foreach (HKCategoryTypeIdentifier value in Enum.GetValues (typeof (HKCategoryTypeIdentifier))) {
#endif

switch (value) {
case HKCategoryTypeIdentifier.SleepAnalysis:
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/HealthKit/QuantityTypeIdentifierTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ public void EnumValues_22351 ()

var failures = new List<string> ();

#if NET
foreach (var value in Enum.GetValues<HKQuantityTypeIdentifier> ()) {
#else
foreach (HKQuantityTypeIdentifier value in Enum.GetValues (typeof (HKQuantityTypeIdentifier))) {
#endif

// we need to have version checks for anything added after iOS 8.0
switch (value) {
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/Metal/MTLDeviceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ public void ReturnReleaseTest ()
Console.WriteLine ($"This device supports feature set: {fs}: {device.SupportsFeatureSet (fs)}");
}
if (TestRuntime.CheckXcodeVersion (11, 0)) {
#if NET
foreach (var gf in Enum.GetValues<MTLGpuFamily> ()) {
#else
foreach (MTLGpuFamily gf in Enum.GetValues (typeof (MTLGpuFamily))) {
#endif
Console.WriteLine ($"This device supports Gpu family: {gf}: {device.SupportsFamily (gf)}");
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/NaturalLanguage/EmbeddingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public void Vector ()
{
TestRuntime.AssertXcodeVersion (11, 0);

#if NET
foreach (var v in Enum.GetValues<NLLanguage> ()) {
#else
foreach (NLLanguage v in Enum.GetValues (typeof (NLLanguage))) {
#endif
if (v == NLLanguage.Unevaluated)
continue; // this is not a value provided by Apple.

Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/NaturalLanguage/NLTaggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public void GetModels ()
{
TestRuntime.AssertXcodeVersion (11, 0);
using (var tagger = new NLTagger (NLTagScheme.LexicalClass) { String = Text }) {
#if NET
foreach (var scheme in typeof (NLTagScheme).GetEnumValues ()) {
#else
foreach (NLTagScheme scheme in Enum.GetValues (typeof (NLTagScheme))) {
#endif
var constant = ((NLTagScheme) scheme).GetConstant ();
if (constant is null)
continue; // can vary by SDK version
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/ObjCRuntime/RegistrarTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,11 @@ public virtual void TestNativeEnum1 (NSWritingDirection twd, int a, long b)
[Export ("testNativeEnum3:a:b:")]
public virtual void TestNativeEnum1 (UITextWritingDirection twd, int a, long b)
{
#if NET
Assert.That (Enum.GetValues<UITextWritingDirection> (), Contains.Item (twd), "TestNativeEnum3");
#else
Assert.That (Enum.GetValues (typeof (UITextWritingDirection)), Contains.Item (twd), "TestNativeEnum3");
#endif
Assert.AreEqual (31415, a, "TestNativeEnum3 a");
Assert.AreEqual (3141592, b, "TestNativeEnum3 b");
}
Expand Down
4 changes: 4 additions & 0 deletions tests/monotouch-test/SceneKit/SCNGeometrySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public void SCNGeometrySource_FromDataTest ()
Asserts.EnsureMountainLion ();
#pragma warning disable 0219
SCNGeometrySource d = SCNGeometrySource.FromData (new NSData (), SCNGeometrySourceSemantic.Color, 1, false, 1, 1, 1, 1);
#if NET
foreach (var s in Enum.GetValues<SCNGeometrySourceSemantics> ()) {
#else
foreach (SCNGeometrySourceSemantics s in Enum.GetValues (typeof (SCNGeometrySourceSemantics))) {
#endif
if (!isValidEnumForPlatform (s))
continue;
d = SCNGeometrySource.FromData (new NSData (), s, 1, false, 1, 1, 1, 1);
Expand Down
4 changes: 4 additions & 0 deletions tests/xharness/TestLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ static string GetLabel<T> (this T self) where T : Enum

public static bool TryGetLabel<T> (this string self, out T? label) where T : Enum
{
#if NET
foreach (var obj in Enum.GetValues<T> ()) {
#else
foreach (var obj in Enum.GetValues (typeof (T))) {
#endif
if (obj is T value && value.GetLabel () == self) {
label = value;
return true;
Expand Down
4 changes: 4 additions & 0 deletions tests/xharness/Xharness.Tests/Jenkins/TestSelectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ public void EnableSeveralTests ()
selection.SetEnabled (TestLabel.All, false);
selection.SetEnabled (TestLabel.Bcl, true);
selection.SetEnabled (TestLabel.Monotouch, true);
#if NET
foreach (var obj in Enum.GetValues<TestLabel> ()) {
#else
foreach (var obj in Enum.GetValues (typeof (TestLabel))) {
#endif
if (obj is TestLabel label) {
switch (label) {
case TestLabel.All:
Expand Down
4 changes: 4 additions & 0 deletions tools/common/Optimizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,11 @@ void ParseOption (ApplePlatform platform, string option, List<ProductException>
values [i] = enabled;
}
if (!found)
#if NET
messages.Add (ErrorHelper.CreateWarning (132, Errors.MX0132, opt, string.Join (", ", Enum.GetValues<Opt> ().Where (o => Array.IndexOf (valid_platforms [(int) o], platform) >= 0).Select (o => opt_names [(int) o]))));
#else
messages.Add (ErrorHelper.CreateWarning (132, Errors.MX0132, opt, string.Join (", ", Enum.GetValues (typeof (Opt)).Cast<Opt> ().Where (o => Array.IndexOf (valid_platforms [(int) o], platform) >= 0).Select (o => opt_names [(int) o]))));
#endif
}
}

Expand Down