-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
TypeConverterAttribute.cs
70 lines (60 loc) · 2.78 KB
/
TypeConverterAttribute.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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 what type to use as a converter for the object this attribute is
/// bound to. This class cannot be inherited.
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public sealed class TypeConverterAttribute : Attribute
{
/// <summary>
/// Specifies the type to use as a converter for the object this attribute is
/// bound to. This <see langword='static '/>field is read-only.
/// </summary>
public static readonly TypeConverterAttribute Default = new TypeConverterAttribute();
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/>
/// class with the default type converter, which is an empty string ("").
/// </summary>
public TypeConverterAttribute()
{
ConverterTypeName = string.Empty;
}
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/>
/// class, using the specified type as the data converter for the object this attribute
/// is bound to.
/// </summary>
public TypeConverterAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type)
{
ArgumentNullException.ThrowIfNull(type);
ConverterTypeName = type.AssemblyQualifiedName!;
}
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.TypeConverterAttribute'/>
/// class, using the specified type name as the data converter for the object this attribute
/// is bound to.
/// </summary>
public TypeConverterAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName)
{
ArgumentNullException.ThrowIfNull(typeName);
ConverterTypeName = typeName;
}
/// <summary>
/// Gets the fully qualified type name of the <see cref='System.Type'/> to use as a
/// converter for the object this attribute is bound to.
/// </summary>
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
public string ConverterTypeName { get; }
public override bool Equals([NotNullWhen(true)] object? obj)
{
return
obj is TypeConverterAttribute other &&
other.ConverterTypeName == ConverterTypeName;
}
public override int GetHashCode() => ConverterTypeName.GetHashCode();
}
}