Skip to content

Commit 3cea3ab

Browse files
fix(audience-sample-app): resolve CS8601 nullable warnings
Two warnings flagged by Unity's C# compiler in AudienceSample.cs. OnSendCustomEvent: the dict was Dictionary<string,object> but `props` (JsonReader.DeserializeObject result) is nullable. Now we only insert the "properties" key when non-null. Side-benefit: cleaner JSON output when no props were entered (key omitted vs serialised as null). RedactPublishableKey: signature changed from `string? Redact(string?)` to `string Redact(string)`. The only caller already guards with !string.IsNullOrEmpty before invoking, so the prior nullable parameter + early-return-null path was dead. Non-nullable signature lets the dict insertion in BuildInitConfigEcho compile cleanly.
1 parent 2e36abf commit 3cea3ab

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

examples/audience/Assets/SampleApp/Scripts/AudienceSample.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ private void OnSendCustomEvent() => RunAndLog("track()", () =>
154154
var f = CaptureCustomEventForm();
155155
var props = string.IsNullOrEmpty(f.RawProps) ? null : JsonReader.DeserializeObject(f.RawProps);
156156
ImmutableAudience.Track(f.Name, props);
157-
return Json.Serialize(new Dictionary<string, object> { ["event"] = f.Name, ["properties"] = props }, 2);
157+
var echo = new Dictionary<string, object> { ["event"] = f.Name };
158+
if (props != null) echo["properties"] = props;
159+
return Json.Serialize(echo, 2);
158160
});
159161

160162
// ---- SDK action handlers: consent ----
@@ -349,12 +351,13 @@ private static Dictionary<string, object> BuildConfigEcho(AudienceConfig config)
349351
}
350352

351353
// Keeps the pk_imapik-test- / pk_imapik- prefix visible; masks the rest.
352-
private static string? RedactPublishableKey(string? key)
354+
// Caller must guard against null/empty; signature non-nullable so the
355+
// dictionary insertion in BuildInitConfigEcho doesn't trip CS8601.
356+
private static string RedactPublishableKey(string key)
353357
{
354-
if (string.IsNullOrEmpty(key)) return key;
355358
const int PrefixChars = 16;
356359
const string Mask = "…****";
357-
return key!.Length <= PrefixChars ? Mask : key.Substring(0, PrefixChars) + Mask;
360+
return key.Length <= PrefixChars ? Mask : key.Substring(0, PrefixChars) + Mask;
358361
}
359362

360363
// ---- Identity helpers ----

0 commit comments

Comments
 (0)