Migrate to more privacy helper extensions

This commit is contained in:
Ske
2020-06-21 15:51:08 +02:00
parent 84d5adf907
commit dcffbef805
7 changed files with 81 additions and 45 deletions

View File

@@ -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