Skip to content

Commit 7c8d867

Browse files
refactor(audience-sdk): introduce IdentityTypeExtensions.ParseLowercaseString
Adds the inverse of ToLowercaseString so callers reading user-supplied or wire-format identity strings can round-trip back into the enum without hand-rolling another switch. - IdentityType.cs: adds IdentityTypeExtensions.ParseLowercaseString, the case-insensitive inverse of ToLowercaseString. Falls back to Custom for unknown / empty values; never throws. - AudienceSample.cs: ParseIdentityType reverse mapper delegates to IdentityTypeExtensions.ParseLowercaseString instead of hand-rolling its own switch.
1 parent 426ff4b commit 7c8d867

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,7 @@ private void ResetIdentityMirror()
375375
// Parses a wire-format identity string (e.g. "steam") back into the
376376
// IdentityType enum the SDK now requires. Falls back to Custom for
377377
// unknown or empty values.
378-
private static IdentityType ParseIdentityType(string? value) => (value ?? "").ToLowerInvariant() switch
379-
{
380-
"passport" => IdentityType.Passport,
381-
"steam" => IdentityType.Steam,
382-
"epic" => IdentityType.Epic,
383-
"google" => IdentityType.Google,
384-
"apple" => IdentityType.Apple,
385-
"discord" => IdentityType.Discord,
386-
"email" => IdentityType.Email,
387-
_ => IdentityType.Custom,
388-
};
378+
private static IdentityType ParseIdentityType(string? value) =>
379+
IdentityTypeExtensions.ParseLowercaseString(value);
389380
}
390381
}

src/Packages/Audience/Runtime/IdentityType.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,18 @@ internal static class IdentityTypeExtensions
5656
_ => throw new System.ArgumentOutOfRangeException(nameof(type), type,
5757
"Unknown IdentityType value; cast an out-of-range value."),
5858
};
59+
60+
internal static IdentityType ParseLowercaseString(string? value) =>
61+
(value ?? string.Empty).ToLowerInvariant() switch
62+
{
63+
"passport" => IdentityType.Passport,
64+
"steam" => IdentityType.Steam,
65+
"epic" => IdentityType.Epic,
66+
"google" => IdentityType.Google,
67+
"apple" => IdentityType.Apple,
68+
"discord" => IdentityType.Discord,
69+
"email" => IdentityType.Email,
70+
_ => IdentityType.Custom,
71+
};
5972
}
6073
}

0 commit comments

Comments
 (0)