Skip to content

Commit

Permalink
Cache EntitlementExtensions.AllKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Nov 30, 2018
1 parent 44b2fee commit 21b7270
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Xamarin.MacDev/EntitlementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ public static class EntitlementKeys
public const string Siri = "com.apple.developer.siri";
public const string APS = "aps-environment";

public static IEnumerable<string> AllKeys {
get {
var entitlementKeys = typeof (EntitlementKeys).GetFields (BindingFlags.Public | BindingFlags.Static).
Where (f => f.FieldType == typeof (string)).
Select (field => (string) field.GetValue (null)).
ToList ();
static string[] allKeys;

return entitlementKeys;
public static string[] AllKeys {
get {
if (allKeys == null) {
allKeys = typeof (EntitlementKeys).GetFields (BindingFlags.Public | BindingFlags.Static).
Where (f => f.FieldType == typeof (string)).
Select (field => (string) field.GetValue (null)).
ToArray ();
}

return allKeys;
}
}
}
Expand Down Expand Up @@ -158,13 +162,14 @@ public static void SetPassBookIdentifiers (this PDictionary dict, PArray value)
dict[EntitlementKeys.PassBookIdentifiers] = value;
}

public static IEnumerable<string> GetEntitlementKeys (this PDictionary dict)
public static List<string> GetEntitlementKeys (this PDictionary dict)
{
var enabledEntitlements = new List<string> ();
var keys = EntitlementKeys.AllKeys;

foreach (var key in EntitlementKeys.AllKeys) {
if (dict.ContainsKey (key))
enabledEntitlements.Add (key);
for (int i = 0; i < keys.Length; i++) {
if (dict.ContainsKey (keys[i]))
enabledEntitlements.Add (keys[i]);
}

return enabledEntitlements;
Expand Down

0 comments on commit 21b7270

Please sign in to comment.