using System; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.Utility; namespace Robust.Shared.ViewVariables { public static class ViewVariablesUtility { /// /// Check whether this type has any fields or properties with the , /// i.e. whether there are any members that are visible in a VV window. /// /// /// This is quite an expensive operation, don't use it lightly. /// /// The type to check. /// True if there are members with the attribute, false otherwise. public static bool TypeHasVisibleMembers(Type type) { return type.GetAllFields().Cast().Concat(type.GetAllProperties()) .Any(f => TryGetViewVariablesAccess(f, out _)); } /// /// Gets the defined for the member, if defined. /// /// The member to check access for. /// The found access. Will be null if no access is defined /// True if access is defined, false if not. public static bool TryGetViewVariablesAccess(MemberInfo info, [NotNullWhen(true)] out VVAccess? access) { if (info.TryGetCustomAttribute(out var vv)) { access = vv.Access; return true; } if (info.HasCustomAttribute() || info.HasCustomAttribute()) { access = VVAccess.ReadWrite; return true; } access = null; return false; } } }