-
Notifications
You must be signed in to change notification settings - Fork 0
/
CopyFromTypeAttributeProvider.cs
162 lines (137 loc) · 4.28 KB
/
CopyFromTypeAttributeProvider.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright (c) Piotr Stenke. All rights reserved.
// Licensed under the MIT license.
namespace Durian.Analysis.CopyFrom
{
/// <summary>
/// <see cref="ISourceTextProvider"/> that creates syntax tree of the <c>Durian.CopyFromTypeAttribute</c> class.
/// </summary>
public sealed class CopyFromTypeAttributeProvider : SourceTextProvider
{
/// <summary>
/// Name of the 'AdditionalNodes' property.
/// </summary>
public const string AdditionalNodes = CopyFromMethodAttributeProvider.AdditionalNodes;
/// <summary>
/// Name of the 'AddUsings' property.
/// </summary>
public const string AddUsings = CopyFromMethodAttributeProvider.AddUsings;
/// <summary>
/// Full name of the provided type.
/// </summary>
public const string FullName = Namespace + "." + TypeName;
/// <summary>
/// Name of the 'HandleSpecialMembers' property.
/// </summary>
public const string HandleSpecialMembers = "HandleSpecialMembers";
/// <summary>
/// Namespace the provided type is located in.
/// </summary>
public const string Namespace = DurianStrings.MainNamespace;
/// <summary>
/// Name of the 'Order' property.
/// </summary>
public const string Order = "Order";
/// <summary>
/// Name of the 'PartialPart' property.
/// </summary>
public const string PartialPart = "PartialPart";
/// <summary>
/// Name of the 'Source' property.
/// </summary>
public const string Source = CopyFromMethodAttributeProvider.Source;
/// <summary>
/// Name of the 'SourceType' property.
/// </summary>
public const string SourceType = "SourceType";
/// <summary>
/// Name of the provided type.
/// </summary>
public const string TypeName = "CopyFromTypeAttribute";
/// <summary>
/// Initializes a new instance of the <see cref="CopyFromTypeAttributeProvider"/> class.
/// </summary>
public CopyFromTypeAttributeProvider()
{
}
/// <inheritdoc/>
public override string GetFullName()
{
return FullName;
}
/// <inheritdoc/>
public override string GetNamespace()
{
return Namespace;
}
/// <inheritdoc/>
public override string GetText()
{
return
@$"using System;
using System.Diagnostics;
using Durian.Configuration;
#nullable enable
namespace {Namespace}
{{
/// <summary>
/// Specifies that implementation of a specific member should be copied from an external source.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false, AllowMultiple = true)]
[Conditional(""DEBUG"")]
public sealed class {TypeName} : Attribute
{{
/// <summary>
/// Determines which non-standard nodes from the target type to include in the generated source.
/// </summary>
public {CopyFromAdditionalNodesProvider.TypeName} {AdditionalNodes} {{ get; set; }}
/// <summary>
/// Specifies, which namespaces should be imported for the generated code.
/// </summary>
public string[]? {AddUsings} {{ get; set; }}
/// <summary>
/// Determines whether to automatically replace name of the target type in constructor, destructor and operator declarations. Defaults to <see langword=""true""/>.
/// </summary>
public bool {HandleSpecialMembers} {{ get; set; }} = true;
/// <summary>
/// Order in which multiple <see cref=""{TypeName}""/>s are applied.
/// </summary>
public int {Order} {{ get; set; }}
/// <summary>
/// Partial part of the source type to copy the implementation from.
/// </summary>
public string? {PartialPart} {{ get; set; }}
/// <summary>
/// Source of the copied implementation.
/// </summary>
public string? {Source} {{ get; }}
/// <summary>
/// Source type of the copied implementation.
/// </summary>
public Type? {SourceType} {{ get; }}
/// <summary>
/// Initializes a new instance of the <see cref=""{TypeName}""/>.
/// </summary>
/// <param name=""sourceType"">Source type of the copied implementation.</param>
public {TypeName}(Type sourceType)
{{
{SourceType} = sourceType;
}}
/// <summary>
/// Initializes a new instance of the <see cref=""{TypeName}""/>.
/// </summary>
/// <param name=""source"">Source of the copied implementation.</param>
public {TypeName}(string source)
{{
{Source} = source;
}}
}}
}}
";
}
/// <inheritdoc/>
public override string GetTypeName()
{
return TypeName;
}
}
}