2016-12-15 13:15:49 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Components
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Indicates that a component is required by another component.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// fixme
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <para>This attribute is *not* inherited. This means that a component class inheriting from
|
2016-12-15 13:15:49 +01:00
|
|
|
|
/// another component class does *not* inherit its requirements. However, the bootloader checks
|
|
|
|
|
|
/// the *interfaces* of every component for their requirements, so requirements declared on
|
|
|
|
|
|
/// interfaces are inherited by every component class implementing the interface.</para>
|
|
|
|
|
|
/// <para>When targetting a class, indicates a dependency on the component which must be enabled,
|
|
|
|
|
|
/// unless the requirement has explicitely been declared as weak (and then, only if the component
|
|
|
|
|
|
/// is enabled).</para>
|
2017-07-20 11:21:28 +02:00
|
|
|
|
/// <para>When targetting an interface, indicates a dependency on enabled components implementing
|
|
|
|
|
|
/// the interface. It could be no component at all, unless the requirement has explicitely been
|
2016-12-15 13:15:49 +01:00
|
|
|
|
/// declared as strong (and at least one component must be enabled).</para>
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
|
|
|
|
|
|
public class RequiredComponentAttribute : Attribute
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="RequiredComponentAttribute"/> class.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="requiringType">The type of the required component.</param>
|
|
|
|
|
|
public RequiredComponentAttribute(Type requiringType)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (typeof(IUmbracoComponent).IsAssignableFrom(requiringType) == false)
|
|
|
|
|
|
throw new ArgumentException($"Type {requiringType.FullName} is invalid here because it does not implement {typeof(IUmbracoComponent).FullName}.");
|
|
|
|
|
|
RequiringType = requiringType;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the required type.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Type RequiringType { get; }
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|