Files
RobustToolbox/Robust.Shared/ViewVariables/ViewVariablesManagerShared.cs
T
AcruidandGitHub 2183cd7ca1 Massive Namespace Cleanup (#1544)
* Removed the Interfaces folder.
* All objects inside the GameObjects subfolders are now in the GameObjects namespace.
* Added a Resharper DotSettings file to mark the GameObjects subfolders as not providing namespaces.
* Simplified Robust.client.Graphics namespace.
* Automated remove redundant using statements.
2021-02-10 23:27:19 -08:00

42 lines
1.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
namespace Robust.Shared.ViewVariables
{
internal class ViewVariablesManagerShared
{
private readonly Dictionary<Type, HashSet<object>> _cachedTraits = new();
/// <summary>
/// Figures out which VV traits an object type has. This method is in shared so the client and server agree on this mess.
/// </summary>
/// <seealso cref="ViewVariablesBlobMetadata.Traits"/>
public ICollection<object> TraitIdsFor(Type type)
{
if (!_cachedTraits.TryGetValue(type, out var traits))
{
traits = new HashSet<object>();
_cachedTraits.Add(type, traits);
if (ViewVariablesUtility.TypeHasVisibleMembers(type))
{
traits.Add(ViewVariablesTraits.Members);
}
if (typeof(IEnumerable).IsAssignableFrom(type))
{
traits.Add(ViewVariablesTraits.Enumerable);
}
if (typeof(IEntity).IsAssignableFrom(type))
{
traits.Add(ViewVariablesTraits.Entity);
}
}
return traits;
}
}
}