/
DesignOnlyAttribute.cs
53 lines (44 loc) · 2.05 KB
/
DesignOnlyAttribute.cs
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
43
44
45
46
47
48
49
50
51
52
53
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
namespace System.ComponentModel
{
/// <summary>
/// Specifies whether a property can only be set at design time.
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public sealed class DesignOnlyAttribute : Attribute
{
/// <summary>
/// Specifies that a property can be set only at design time.
/// This <see langword='static'/> field is read-only.
/// </summary>
public static readonly DesignOnlyAttribute Yes = new DesignOnlyAttribute(true);
/// <summary>
/// Specifies that a property can be set at design time or at run time.
/// This <see langword='static'/> field is read-only.
/// </summary>
public static readonly DesignOnlyAttribute No = new DesignOnlyAttribute(false);
/// <summary>
/// Specifies the default value for the <see cref='System.ComponentModel.DesignOnlyAttribute'/>,
/// which is <see cref='System.ComponentModel.DesignOnlyAttribute.No'/>.
/// This <see langword='static'/> field is read-only.
/// </summary>
public static readonly DesignOnlyAttribute Default = No;
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignOnlyAttribute'/> class.
/// </summary>
public DesignOnlyAttribute(bool isDesignOnly)
{
IsDesignOnly = isDesignOnly;
}
/// <summary>
/// Gets a value indicating whether a property can be set only at design time.
/// </summary>
public bool IsDesignOnly { get; }
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is DesignOnlyAttribute other && other.IsDesignOnly == IsDesignOnly;
public override int GetHashCode() => IsDesignOnly.GetHashCode();
public override bool IsDefaultAttribute() => IsDesignOnly == Default.IsDesignOnly;
}
}