Skip to content

Commit 22a4d2e

Browse files
olegoidjstedfast
authored andcommitted
Add AllKeys property and GetEntitlementsKeys method (#20)
* Add AllKeys property and GetEntitlementsKeys method * Fix method name GetEntitlementsKeys -> GetEntitlementKeys
1 parent d3931ff commit 22a4d2e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Xamarin.MacDev/EntitlementExtensions.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// Copyright (c) 2016 Xamarin Inc. (www.xamarin.com)
77
//
88

9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Reflection;
12+
913
namespace Xamarin.MacDev
1014
{
1115
public static class EntitlementKeys
@@ -31,6 +35,17 @@ public static class EntitlementKeys
3135
public const string GetTaskAllow = "get-task-allow";
3236
public const string Siri = "com.apple.developer.siri";
3337
public const string APS = "aps-environment";
38+
39+
public static IEnumerable<string> AllKeys {
40+
get {
41+
var entitlementKeys = typeof (EntitlementKeys).GetFields (BindingFlags.Public | BindingFlags.Static).
42+
Where (f => f.FieldType == typeof (string)).
43+
Select (field => (string) field.GetValue (null)).
44+
ToList ();
45+
46+
return entitlementKeys;
47+
}
48+
}
3449
}
3550

3651
public static class EntitlementExtensions
@@ -139,5 +154,17 @@ public static void SetPassBookIdentifiers (this PDictionary dict, PArray value)
139154
else
140155
dict[EntitlementKeys.PassBookIdentifiers] = value;
141156
}
157+
158+
public static IEnumerable<string> GetEntitlementKeys (this PDictionary dict)
159+
{
160+
var enabledEntitlements = new List<string> ();
161+
162+
foreach (var key in EntitlementKeys.AllKeys) {
163+
if (dict.ContainsKey (key))
164+
enabledEntitlements.Add (key);
165+
}
166+
167+
return enabledEntitlements;
168+
}
142169
}
143170
}

0 commit comments

Comments
 (0)