com.wallstop-studios.dxmessaging 2.0.0-rc26.4 → 2.0.0-rc26.5

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.
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 87d96cdf2fc74f40ba77ae0d157be964
3
+ timeCreated: 1749850608
@@ -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
- for (int i = 0; i < fieldsToInject.Length; i++)
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
- constructorParams.Append($"{fieldType} {fieldName}");
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.dxmessaging",
3
- "version": "2.0.0-rc26.4",
3
+ "version": "2.0.0-rc26.5",
4
4
  "displayName": "DxMessaging",
5
5
  "description": "Synchronous Event Bus for Unity",
6
6
  "unity": "2021.3",
@@ -36,3 +36,4 @@
36
36
 
37
37
 
38
38
 
39
+