Skip to content

Commit

Permalink
Add AllKeys property and GetEntitlementsKeys method (#20)
Browse files Browse the repository at this point in the history
* Add AllKeys property and GetEntitlementsKeys method

* Fix method name GetEntitlementsKeys -> GetEntitlementKeys
  • Loading branch information
olegoid authored and jstedfast committed Jan 5, 2018
1 parent d3931ff commit 22a4d2e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Xamarin.MacDev/EntitlementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
// Copyright (c) 2016 Xamarin Inc. (www.xamarin.com)
//

using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Xamarin.MacDev
{
public static class EntitlementKeys
Expand All @@ -31,6 +35,17 @@ public static class EntitlementKeys
public const string GetTaskAllow = "get-task-allow";
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 ();

return entitlementKeys;
}
}
}

public static class EntitlementExtensions
Expand Down Expand Up @@ -139,5 +154,17 @@ public static void SetPassBookIdentifiers (this PDictionary dict, PArray value)
else
dict[EntitlementKeys.PassBookIdentifiers] = value;
}

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

foreach (var key in EntitlementKeys.AllKeys) {
if (dict.ContainsKey (key))
enabledEntitlements.Add (key);
}

return enabledEntitlements;
}
}
}

0 comments on commit 22a4d2e

Please sign in to comment.