Migration Guide to 5.x
Confused about "Migration Guide to 5.x"?
Let us know how we can improve our documentation:
This guide will help you migrate your code if upgrading the Unity Chat SDK to the 5.x version.
The primary change was to replace enums with custom structs. This change makes the SDK much more resilient to API changes, but it may require you to refactor parts of your code that rely on the enums' compilation constant property.
Affected Types
Copied!Confused about "Affected Types"?
Let us know how we can improve our documentation:
Here’s a full list of enum types that got replaced with a struct:
Namespace -> Type
Copied!StreamChat.Core.Models
- >StreamMessageType
StreamChat.Core.Responses
->StreamImageCropType
StreamChat.Core.Responses
->StreamImageResizeType
StreamChat.Core.InternalDTO.Models
->AutomodBehaviourType
StreamChat.Core.InternalDTO.Models
->AutomodType
StreamChat.Core.InternalDTO.Models
->BlockListOptionsBehavior
StreamChat.Core.InternalDTO.Models
->ImageCropType
StreamChat.Core.InternalDTO.Models
->ImageResizeType
StreamChat.Core.InternalDTO.Models
->MessageType
StreamChat.Core.InternalDTO.Models
->PushProviderType
StreamChat.Core.InternalDTO.Requests
->CreateCallRequestType
StreamChat.Core.InternalDTO.Requests
->CreatePollRequestVotingVisibility
StreamChat.Core.InternalDTO.Requests
->MessageRequestType
StreamChat.Core.InternalDTO.Requests
->TranslateMessageRequestLanguage
StreamChat.Core.InternalDTO.Requests
->UpdatePollRequestVotingVisibility
StreamChat.Core.InternalDTO.Responses
->ChannelMemberResponseRole
Non-breaking Changes
Copied!Confused about "Non-breaking Changes"?
Let us know how we can improve our documentation:
In many cases, the migration from enums to structs will not require any code changes at all, as the syntax remains the same.
Variable Declaration and Assignment
Copied!Confused about "Variable Declaration and Assignment"?
Let us know how we can improve our documentation:
Method Parameters and Return Types
Copied!Confused about "Method Parameters and Return Types"?
Let us know how we can improve our documentation:
Basic Equality Comparisons
Copied!Confused about "Basic Equality Comparisons"?
Let us know how we can improve our documentation:
Breaking Changes and How to Fix Them
Copied!Confused about "Breaking Changes and How to Fix Them"?
Let us know how we can improve our documentation:
While many use cases will work the same, there are some scenarios where the change from enums to structs will require code modifications.
Switch Statements
Copied!Confused about "Switch Statements"?
Let us know how we can improve our documentation:
The most common scenario requiring rewriting the code is when an enum is used in a switch statement. Such cases must be converted to a chain of if/else statements or use the latest pattern-matching syntax in C# 7.0+.
Initialization and Default Values
Copied!Confused about "Initialization and Default Values"?
Let us know how we can improve our documentation:
Enums have an implicit default value of 0. Structs do not, and you may need to explicitly initialize the struct where an enum default was previously used.
Old code (with enum):
Copied!New code (with struct):
Copied!Const assignment
Copied!Confused about "Const assignment"?
Let us know how we can improve our documentation:
Enums were allowed to be used in compile-time constants.
Old code (with enum):
Copied!New code (with struct):
Copied!Structs cannot be const
because they are reference types, so you cannot assign them as compile-time constants. Instead, the closest alternative is to use static readonly
.
This introduces a slight difference: while const
values are replaced at compile-time, static readonly
values are evaluated at runtime. This means that code relying on const
behavior (e.g., embedded in assemblies or libraries) might require adjustment to work with the new static readonly
fields.
Summary
Copied!Confused about "Summary"?
Let us know how we can improve our documentation:
This concludes the migration guidance on upgrading your project to Stream Chat SDK for Unity 5.x. If you've encountered any issues not mentioned in this guide or have any questions about the migration process, please don't hesitate to contact us. We're here to assist you and ensure a smooth transition to your projects’ latest version of the SDK.