dotnet / dotnet/macios

Add a strongly typed SRSensorReader.RequestAuthorization overload

Open
#18,464 0 comments 1 reaction 0 assignees View on GitHub
copilot-candidate enhancement good first issue help wanted
Dominant language
C#
Stars
2.9k
Forks
576
Avg merge
2d 12h
Merged PRs (30d)
123

Description

See customer struggle here:

https://discord.com/channels/732297728826277939/732297808148824115/1120406222974234685

They were doing this:

```cs
var sensors = new NSString[] {
new NSString(SRSensor.MessagesUsageReport.ToString()),
new NSString(SRSensor.PhoneUsageReport.ToString()),
new NSString(SRSensor.DeviceUsageReport.ToString())
};
var nsset = new NSSet(sensors);
await SRSensorReader.RequestAuthorizationAsync(nsset);
```

when the correct is this:

```cs
var sensors = new NSString[] {
new NSString(SRSensor.MessagesUsageReport.GetConstant()),
new NSString(SRSensor.PhoneUsageReport.GetConstant()),
new NSString(SRSensor.DeviceUsageReport.GetConstant())
};
var nsset = new NSSet(sensors);
await SRSensorReader.RequestAuthorizationAsync(nsset);
```

However, we should be able to improve the API to something like this:

```cs
var sensors = new [] {
SRSensor.MessagesUsageReport,
SRSensor.PhoneUsageReport,
SRSensor.DeviceUsageReport,
};
await SRSensorReader.RequestAuthorization (sensors);
```

and then we just do the right thing in this overload, making it impossible for customers to make this kind of mistake again.

Just to clarify, we should add a manual overload taking an array of SRSensor values:

```cs
void RequestAuthorization (SRSensor[] sensors, Action completion);
```

Even better if there was a way to make the async overload take a params array:

```cs
Task RequestAuthorizationAsync (params SRSensor[] sensors);
```

and then the calling code becomes:

```cs
await SRSensorReader.RequestAuthorization (
SRSensor.MessagesUsageReport,
SRSensor.PhoneUsageReport,
SRSensor.DeviceUsageReport);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.