internal static bool IsPermissionGranted(CodeAccessPermission requestedPermission) { try { // Try and get this permission requestedPermission.Demand(); return true; } catch { return false; } }
// A better implementation would cache this information over the lifetime of the application, // so the permission only needs to be evaluated once. private bool CheckPermission(CodeAccessPermission requestedPermission) { try { // Try to get this permission. requestedPermission.Demand(); return true; } catch { return false; } }
private static void Demand(CodeAccessPermission permission) { permission.Demand(); }