mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-07 06:17:55 +00:00
Migrate to more privacy helper extensions
This commit is contained in:
parent
84d5adf907
commit
dcffbef805
7 changed files with 81 additions and 45 deletions
|
|
@ -11,8 +11,23 @@
|
|||
public static bool CanAccess(this PrivacyLevel level, LookupContext ctx) =>
|
||||
level == PrivacyLevel.Public || ctx == LookupContext.ByOwner;
|
||||
|
||||
public static string Name(this PrivacyLevel level) =>
|
||||
public static string LevelName(this PrivacyLevel level) =>
|
||||
level == PrivacyLevel.Public ? "public" : "private";
|
||||
|
||||
public static T Get<T>(this PrivacyLevel level, LookupContext ctx, T input, T fallback = default) =>
|
||||
level.CanAccess(ctx) ? input : fallback;
|
||||
|
||||
public static bool TryGet<T>(this PrivacyLevel level, LookupContext ctx, T input, out T output, T absentValue = default)
|
||||
{
|
||||
output = default;
|
||||
if (!level.CanAccess(ctx))
|
||||
return false;
|
||||
if (Equals(input, absentValue))
|
||||
return false;
|
||||
|
||||
output = input;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public enum LookupContext
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue