Skip to content

Commit df7dab1

Browse files
committed
Small improvement, removing magic number.
1 parent 5328178 commit df7dab1

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Microsoft.Toolkit.Services/Services/LinkedIn/LinkedInDataProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public LinkedInDataProvider(LinkedInOAuthTokens tokens, LinkedInPermissions requ
8181
throw new ArgumentException("Missing callback uri");
8282
}
8383

84-
// Check if outside the bounds of the LinkedInPermissions Enum
85-
if (requiredPermissions < 0 || requiredPermissions > (LinkedInPermissions)15)
84+
// Check if its a valid combination of LinkedInPermissions
85+
if ((~(int)LinkedInPermissionsHelpers.AllPermissions & (int)requiredPermissions) == 0)
8686
{
8787
throw new ArgumentException("Error retrieving required permissions");
8888
}

Microsoft.Toolkit.Services/Services/LinkedIn/LinkedInPermissions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ public enum LinkedInPermissions
3737
/// </summary>
3838
WriteShare = 8
3939
}
40+
41+
#pragma warning disable SA1649 // File name should match first type name
42+
internal static class LinkedInPermissionsHelpers
43+
{
44+
/// <summary>
45+
/// Internal AllPermissions for LinkedInPermissions, so we don't expose it. Keep it in sync with <see cref="LinkedInPermissions"/>
46+
/// </summary>
47+
internal const LinkedInPermissions AllPermissions =
48+
LinkedInPermissions.ReadBasicProfile |
49+
LinkedInPermissions.ReadEmailAddress |
50+
LinkedInPermissions.ReadWriteCompanyAdmin |
51+
LinkedInPermissions.WriteShare;
52+
}
53+
#pragma warning restore SA1649 // File name should match first type name
4054
}

0 commit comments

Comments
 (0)