/
DesignerSerializerAttribute.cs
83 lines (73 loc) · 3.08 KB
/
DesignerSerializerAttribute.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
71
72
73
74
75
76
77
78
79
80
81
82
83
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.ComponentModel.Design.Serialization
{
/// <summary>
/// This attribute can be placed on a class to indicate what serialization
/// object should be used to serialize the class at design time.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public sealed class DesignerSerializerAttribute : Attribute
{
private string? _typeId;
/// <summary>
/// Creates a new designer serialization attribute.
/// </summary>
public DesignerSerializerAttribute(Type serializerType, Type baseSerializerType)
{
ArgumentNullException.ThrowIfNull(serializerType);
ArgumentNullException.ThrowIfNull(baseSerializerType);
SerializerTypeName = serializerType.AssemblyQualifiedName;
SerializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
}
/// <summary>
/// Creates a new designer serialization attribute.
/// </summary>
public DesignerSerializerAttribute(string? serializerTypeName, Type baseSerializerType)
{
ArgumentNullException.ThrowIfNull(baseSerializerType);
SerializerTypeName = serializerTypeName;
SerializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
}
/// <summary>
/// Creates a new designer serialization attribute.
/// </summary>
public DesignerSerializerAttribute(string? serializerTypeName, string? baseSerializerTypeName)
{
SerializerTypeName = serializerTypeName;
SerializerBaseTypeName = baseSerializerTypeName;
}
/// <summary>
/// Retrieves the fully qualified type name of the serializer.
/// </summary>
public string? SerializerTypeName { get; }
/// <summary>
/// Retrieves the fully qualified type name of the serializer base type.
/// </summary>
public string? SerializerBaseTypeName { get; }
/// <summary>
/// This defines a unique ID for this attribute type. It is used
/// by filtering algorithms to identify two attributes that are
/// the same type. For most attributes, this just returns the
/// Type instance for the attribute. EditorAttribute overrides
/// this to include the type of the editor base type.
/// </summary>
public override object TypeId
{
get
{
if (_typeId == null)
{
string baseType = SerializerBaseTypeName ?? string.Empty;
int comma = baseType.IndexOf(',');
if (comma != -1)
{
baseType = baseType.Substring(0, comma);
}
_typeId = GetType().FullName + baseType;
}
return _typeId;
}
}
}
}