Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created May 13, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/6c6077982a417d918887 to your computer and use it in GitHub Desktop.
Save vgrem/6c6077982a417d918887 to your computer and use it in GitHub Desktop.
using Newtonsoft.Json.Linq;
namespace SharePoint.Client
{
public class BasePermissions
{
public static BasePermissions ParseFromJson(JObject data)
{
var permissions = new BasePermissions {_low = (uint) data["Low"], _high = (uint) data["High"]};
return permissions;
}
public bool Has(PermissionKind perm)
{
if (perm == PermissionKind.EmptyMask)
return true;
if (perm == PermissionKind.FullMask)
{
if ((_high & short.MaxValue) == short.MaxValue)
return _low == ushort.MaxValue;
return false;
}
var permLow = (int)perm - 1;
var permHigh = 1U;
if (permLow >= 0 && permLow < 32)
return 0 != (_low & (permHigh << permLow));
if (permLow >= 32 && permLow < 64)
return 0 != (_high & (permHigh << permLow - 32));
return false;
}
private uint _high;
private uint _low;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment