private static void CheckPermissionOrException(GoogleDrivePermission permission)
 {
     if (permission.Type != GoogleDrivePermType.anyone && permission.Email == null)
     {
         throw new ArgumentException("This permission type requires an email.");
     }
     if (permission.Type == GoogleDrivePermType.unknown || permission.Role == GoogleDriveRole.unknown)
     {
         throw new ArgumentException("Invalid arguments passed.");
     }
 }
        public static GoogleDriveResultWithData <GoogleDrivePermission> SetResourcePermissions(Connection connection, string fileOrFolderId, GoogleDrivePermission permission)
        {
            CheckConnectionOrException(connection);
            CheckPermissionOrException(permission);

            PermissionsResource.CreateRequest request = connection.Service.Permissions.Create(new Permission()
            {
                EmailAddress = permission.Email,
                Type         = permission.Type.ToString(),
                Role         = permission.Role.ToString()
            }, fileOrFolderId);

            GoogleDriveResultWithData <GoogleDrivePermission> result = ExecuteRequest <PermissionsResource.CreateRequest, Permission, GoogleDriveResultWithData <GoogleDrivePermission> >(request, (resp, res) =>
            {
                res.Data = new GoogleDrivePermission(resp.Id, resp.EmailAddress, permission.Type, permission.Role);
            });

            return(result);
        }