Migrate to more privacy helper extensions
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user