using System; using System.Collections.Generic; using Assets.Exceptions; namespace Assets.Common { [Serializable] public class Metadata { private readonly Dictionary _properties = new Dictionary(); public bool HasProperty(string name) => _properties.ContainsKey(name); public bool HasProperty(string name) => HasProperty(name) && _properties[name] is T; public void SetProperty(string name, T property) { _properties[name] = property; } public T GetProperty(string name) { if (!HasProperty(name)) throw new PropertyAccessException($"Property named \"{name}\" does not exist in this site."); var property = _properties[name]; if (property is T value) return value; throw new PropertyAccessException($"Property named \"{name}\" is of type {property.GetType()} not {typeof(T)}."); } } }