com.wallstop-studios.dxmessaging 2.0.0-rc26.4 → 2.0.0-rc26.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.config/dotnet-tools.json +1 -1
- package/Editor/Analyzers/WallstopStudios.DxMessaging.SourceGenerators.dll +0 -0
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs +10 -0
- package/Runtime/Core/Attributes/DxOptionalParameterAttribute.cs.meta +3 -0
- package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs +29 -6
- package/package.json +3 -1
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
namespace DxMessaging.Core.Attributes
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
|
|
5
|
+
[AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
|
|
6
|
+
public sealed class DxOptionalParameterAttribute : Attribute
|
|
7
|
+
{
|
|
8
|
+
public DxOptionalParameterAttribute() { }
|
|
9
|
+
}
|
|
10
|
+
}
|
package/SourceGenerators/WallstopStudios.DxMessaging.SourceGenerators/DxAutoConstructorGenerator.cs
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
private const string AutoGenConstructorAttrFullName =
|
|
19
19
|
"DxMessaging.Core.Attributes.DxAutoConstructorAttribute";
|
|
20
20
|
|
|
21
|
+
private const string OptionalParameterAttrFullName =
|
|
22
|
+
"DxMessaging.Core.Attributes.DxOptionalParameterAttribute";
|
|
23
|
+
|
|
21
24
|
// Info needed during generation for a valid type
|
|
22
25
|
private record struct TypeToGenerateInfo(
|
|
23
26
|
INamedTypeSymbol TypeSymbol,
|
|
@@ -171,7 +174,6 @@
|
|
|
171
174
|
ImmutableArray<IFieldSymbol> fieldsToInject
|
|
172
175
|
)
|
|
173
176
|
{
|
|
174
|
-
|
|
175
177
|
string namespaceName = typeSymbol.ContainingNamespace.IsGlobalNamespace
|
|
176
178
|
? string.Empty
|
|
177
179
|
: typeSymbol.ContainingNamespace.ToDisplayString();
|
|
@@ -213,18 +215,39 @@
|
|
|
213
215
|
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers
|
|
214
216
|
);
|
|
215
217
|
|
|
216
|
-
|
|
218
|
+
List<(string Type, string Name, bool IsOptional)> parameterDetails = [];
|
|
219
|
+
|
|
220
|
+
foreach (IFieldSymbol field in fieldsToInject)
|
|
217
221
|
{
|
|
218
|
-
IFieldSymbol field = fieldsToInject[i];
|
|
219
222
|
string fieldType = field.Type.ToDisplayString(fieldTypeFormat);
|
|
220
223
|
string fieldName = field.Name;
|
|
224
|
+
bool isOptional = field
|
|
225
|
+
.GetAttributes()
|
|
226
|
+
.Any(attr =>
|
|
227
|
+
string.Equals(
|
|
228
|
+
attr.AttributeClass?.ToDisplayString(),
|
|
229
|
+
OptionalParameterAttrFullName,
|
|
230
|
+
StringComparison.Ordinal
|
|
231
|
+
)
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
parameterDetails.Add((fieldType, fieldName, isOptional));
|
|
235
|
+
constructorBody.AppendLine($"{indent}{indent} this.{fieldName} = {fieldName};");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
for (int i = 0; i < parameterDetails.Count; i++)
|
|
239
|
+
{
|
|
240
|
+
(string Type, string Name, bool IsOptional) p = parameterDetails[i];
|
|
241
|
+
constructorParams.Append($"{p.Type} {p.Name}");
|
|
242
|
+
if (p.IsOptional)
|
|
243
|
+
{
|
|
244
|
+
constructorParams.Append(" = default");
|
|
245
|
+
}
|
|
221
246
|
|
|
222
|
-
|
|
223
|
-
if (i < fieldsToInject.Length - 1)
|
|
247
|
+
if (i < parameterDetails.Count - 1)
|
|
224
248
|
{
|
|
225
249
|
constructorParams.Append(", ");
|
|
226
250
|
}
|
|
227
|
-
constructorBody.AppendLine($"{indent}{indent} this.{fieldName} = {fieldName};");
|
|
228
251
|
}
|
|
229
252
|
|
|
230
253
|
return $$"""
|
package/package.json
CHANGED