using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using Voile.Common.DRM; using Voile.Common.Reflection; namespace Voile.Patchouli.Reflection { public class VoilePluginInfo { internal VoilePluginInfo(Type t) { Type = t; } private Type Type { get; } public string TypeName { get => Type.Name; } public int Id { get; internal set; } public VoileSubsystemType Subsystem { get; internal set; } private object _instance; public object GetPluginInstance() { if (_instance != null) return _instance; ConstructorInfo? constructorInfo = Type.GetConstructor(new Type[0] { }); if (constructorInfo == null) { throw new VoileReflectionException(String.Format("{0} does not provide a parameterless constructor.", TypeName)); } object result = constructorInfo.Invoke(new object[0] { }); _instance = result; return result; } private bool checkedNeededEntitlement; private Guid? _neededEntitlement; public Guid? NeededEntitlement { get { if (checkedNeededEntitlement) return _neededEntitlement; NeedsEntitlementAttribute? needsEntitlementAttribute = Type.GetCustomAttribute(); if (needsEntitlementAttribute != null) { _neededEntitlement = needsEntitlementAttribute.Guid; } checkedNeededEntitlement = true; return _neededEntitlement; } } private bool checkedAutoconfigurable; public bool _autoconfigurable; public bool Autoconfigurable { get { if (checkedAutoconfigurable) return _autoconfigurable; AutoconfigurableAttribute autoconfigurableAttribute = Type.GetCustomAttribute(); _autoconfigurable = autoconfigurableAttribute != null; checkedAutoconfigurable = true; return _autoconfigurable; } } private bool checkedIncomplete; private bool _incomplete; public bool Incomplete { get { if (checkedIncomplete) return _incomplete; IncompleteAttribute incompleteAttribute = Type.GetCustomAttribute(); _incomplete = incompleteAttribute != null; checkedIncomplete = true; return _incomplete; } } private string _displayName; public string DisplayName { get { if (!string.IsNullOrEmpty(_displayName)) return _displayName; DisplayNameAttribute displayNameAttribute = Type.GetCustomAttribute(); if (displayNameAttribute != null) { _displayName = displayNameAttribute.DisplayName; } if (string.IsNullOrEmpty(_displayName)) { _displayName = TypeName; } return _displayName; } } private string _description; public string Description { get { if (!string.IsNullOrEmpty(_description)) return _description; DescriptionAttribute descriptionAttribute = Type.GetCustomAttribute(); if (descriptionAttribute != null) { _description = descriptionAttribute.Desciption; } if (string.IsNullOrEmpty(_description)) { _description = String.Format("TODO: Add {0} to {1}.", nameof(DescriptionAttribute), TypeName); } return Description; } } } }