public static AccessArguments GetAccessArguments(
            [NotNull] this IFieldContainter entityWithFields,
            int userId)
        {
            if (entityWithFields == null)
            {
                throw new ArgumentNullException(nameof(entityWithFields));
            }


            if (entityWithFields is Claim claim)
            {
                return(new AccessArguments(claim, userId));
            }
            if (entityWithFields is Character character)
            {
                return(new AccessArguments(character, userId));
            }
            throw new NotSupportedException($"{entityWithFields.GetType()} is not supported to get fields for.");
        }
Exemplo n.º 2
0
        public static Predicate <FieldWithValue> GetShowForUserPredicate(
            [NotNull] IFieldContainter entityWithFields,
            int userId)
        {
            if (entityWithFields == null)
            {
                throw new ArgumentNullException(nameof(entityWithFields));
            }

            var claim     = entityWithFields as Claim;
            var character = entityWithFields as Character;

            if (claim != null)
            {
                return(f => f.HasViewAccess(new AccessArguments(claim, userId)));
            }
            if (character != null)
            {
                return(f => f.HasViewAccess(new AccessArguments(character, userId)));
            }
            throw new NotSupportedException($"{entityWithFields.GetType()} is not supported to get fields for.");
        }