2016-08-25 15:09:51 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Components
|
|
|
|
|
|
{
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// <summary>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// Indicates that a composer requires another composer.
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// <para>This attribute is *not* inherited. This means that a composer class inheriting from
|
|
|
|
|
|
/// another composer class does *not* inherit its requirements. However, the runtime checks
|
|
|
|
|
|
/// the *interfaces* of every composer for their requirements, so requirements declared on
|
|
|
|
|
|
/// interfaces are inherited by every composer class implementing the interface.</para>
|
|
|
|
|
|
/// <para>When targeting a class, indicates a dependency on the composer which must be enabled,
|
|
|
|
|
|
/// unless the requirement has explicitly been declared as weak (and then, only if the composer
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// is enabled).</para>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// <para>When targeting an interface, indicates a dependency on enabled composers implementing
|
|
|
|
|
|
/// the interface. It could be no composer at all, unless the requirement has explicitly been
|
|
|
|
|
|
/// declared as strong (and at least one composer must be enabled).</para>
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// </remarks>
|
|
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
|
2019-01-04 10:29:29 +01:00
|
|
|
|
public sealed class ComposeAfterAttribute : Attribute
|
2016-08-25 15:09:51 +02:00
|
|
|
|
{
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// <summary>
|
2019-01-04 10:29:29 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="ComposeAfterAttribute"/> class.
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// </summary>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// <param name="requiredType">The type of the required composer.</param>
|
2019-01-04 10:29:29 +01:00
|
|
|
|
public ComposeAfterAttribute(Type requiredType)
|
2016-08-25 15:09:51 +02:00
|
|
|
|
{
|
2019-01-03 21:00:28 +01:00
|
|
|
|
if (typeof(IComposer).IsAssignableFrom(requiredType) == false)
|
|
|
|
|
|
throw new ArgumentException($"Type {requiredType.FullName} is invalid here because it does not implement {typeof(IComposer).FullName}.");
|
2016-08-25 15:09:51 +02:00
|
|
|
|
RequiredType = requiredType;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// <summary>
|
2019-01-04 10:29:29 +01:00
|
|
|
|
/// Initializes a new instance of the <see cref="ComposeAfterAttribute"/> class.
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// </summary>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// <param name="requiredType">The type of the required composer.</param>
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// <param name="weak">A value indicating whether the requirement is weak.</param>
|
2019-01-04 10:29:29 +01:00
|
|
|
|
public ComposeAfterAttribute(Type requiredType, bool weak)
|
2016-09-01 11:25:00 +02:00
|
|
|
|
: this(requiredType)
|
|
|
|
|
|
{
|
|
|
|
|
|
Weak = weak;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets the required type.
|
|
|
|
|
|
/// </summary>
|
2016-08-25 15:09:51 +02:00
|
|
|
|
public Type RequiredType { get; }
|
2016-09-01 11:25:00 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets a value indicating whether the requirement is weak.
|
|
|
|
|
|
/// </summary>
|
2019-01-03 21:00:28 +01:00
|
|
|
|
/// <remarks>Returns <c>true</c> if the requirement is weak (requires the other composer if it
|
|
|
|
|
|
/// is enabled), <c>false</c> if the requirement is strong (requires the other composer to be
|
2016-09-01 11:25:00 +02:00
|
|
|
|
/// enabled), and <c>null</c> if unspecified, in which case it is strong for classes and weak for
|
|
|
|
|
|
/// interfaces.</remarks>
|
|
|
|
|
|
public bool? Weak { get; }
|
2016-08-25 15:09:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|