tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
AuthorityInvokerBase{TAuthority}.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3
5
7{
9 abstract class AuthorityInvokerBase<TAuthority> : IAuthorityInvoker<TAuthority>
10 where TAuthority : IAuthority
11 {
15 protected TAuthority Authority { get; }
16
21 public AuthorityInvokerBase(TAuthority authority)
22 {
23 Authority = authority ?? throw new ArgumentNullException(nameof(authority));
24 }
25
27 IQueryable<TResult> IAuthorityInvoker<TAuthority>.InvokeQueryable<TResult>(Func<TAuthority, IQueryable<TResult>> authorityInvoker)
28 {
29 ArgumentNullException.ThrowIfNull(authorityInvoker);
30 return authorityInvoker(Authority);
31 }
32
34 IQueryable<TApiModel> IAuthorityInvoker<TAuthority>.InvokeTransformableQueryable<TResult, TApiModel, TTransformer>(Func<TAuthority, IQueryable<TResult>> authorityInvoker)
35 {
36 ArgumentNullException.ThrowIfNull(authorityInvoker);
37
38 var queryable = authorityInvoker(Authority);
39
40 if (typeof(EntityId).IsAssignableFrom(typeof(TResult)))
41 queryable = queryable.OrderBy(item => ((EntityId)(object)item).Id!.Value); // order by ID to fix an EFCore warning
42
43 var expression = new TTransformer().Expression;
44 return queryable
45 .Select(expression);
46 }
47 }
48}
Common base of entities with IDs.
Definition EntityId.cs:7
AuthorityInvokerBase(TAuthority authority)
Initializes a new instance of the AuthorityInvokerBase<TAuthority> class.
Business logic for interating with the server.
Definition IAuthority.cs:9
@ Id
Lookup the Api.Models.EntityId.Id of the Models.PermissionSet.