chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
namespace OpenTap
{
    /// <summary>
    /// Ordering constraint for plugin types. This should be used 'before' something else.
    /// This is currently only support by implementations of IStringConvertProvider.
    /// If more than one of these attributes are used, it will try to find a type before all of them.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class BeforeAttribute: Attribute
    {
        readonly ITypeData type;
        /// <summary>
        ///  Creates a BeforeAttribute from a type parameter. This is the safest way, but requires a public C# type.
        /// </summary>
        public BeforeAttribute(Type type)
        {
            this.type = TypeData.FromType(type);
        }
        /// <summary>
        ///  Creates a BeforeAttribute from a string type name..
        /// </summary>
        /// <param name="typeName"></param>
        public BeforeAttribute(string typeName)
        {
            this.type = TypeData.GetTypeData(typeName);
        }
 
        /// <summary>
        /// returns true if the marked type should come before the 'other' type.
        /// This can method can be overridden for more custom 'before' behavior.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public virtual bool Before(ITypeData other)
        {
            if (type != null && Equals(type, other))
                return true;
            return false;
        } 
    }
}