Refactor classes to use record types for improved readability and maintainability#45
Refactor classes to use record types for improved readability and maintainability#45gehongyan wants to merge 2 commits into
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR refactors various classes and structs to use C# record types for improved readability and maintainability. The changes include converting immutable data types to records/record structs, removing manual IEquatable implementations, cleaning up unused imports, modernizing Enum.GetValues usage, and fixing a comment typo.
Changes:
- Converted immutable data types (Card, modules, elements, UserTag) to record types, removing manual equality implementations
- Converted immutable value types (Color, AlphaColor, GradientColor) to readonly record structs
- Incorrectly converted mutable builder classes to records (critical issue)
- Removed unused imports (System.Diagnostics.CodeAnalysis, System.Linq, etc.)
- Modernized Enum.GetValues to use generic syntax
- Fixed typo in BaseKookClient comment
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Kook.Net.Tests.Unit/CardBuilderTests.cs | Modernized Enum.GetValues syntax; removed unused System.Linq import |
| src/Kook.Net.WebSocket/KookSocketClient.Messages.cs | Removed unused Kook.Audio import |
| src/Kook.Net.WebSocket/KookSocketApiClient.cs | Removed unused System.Diagnostics import |
| src/Kook.Net.Rest/Net/Converters/*.cs | Removed unused Kook.API.Rest imports |
| src/Kook.Net.Rest/Entities/Threads/ThreadHelper.cs | Removed unused imports |
| src/Kook.Net.Rest/BaseKookClient.cs | Fixed typo: "any ways" → "anyway" |
| src/Kook.Net.Experimental/Rest/ExperimentalGuildHelper.cs | Removed unused Kook.WebSocket import |
| src/Kook.Net.Core/Entities/Users/UserTag.cs | Converted immutable class to record |
| src/Kook.Net.Core/Entities/Users/Nameplate.cs | Removed unused import |
| src/Kook.Net.Core/Entities/Roles/*.cs | Converted immutable value types to readonly record structs |
| src/Kook.Net.Core/Entities/Messages/Cards/Modules/*.cs | Converted immutable module types to records |
| src/Kook.Net.Core/Entities/Messages/Cards/Modules/Builders/*.cs | CRITICAL: Incorrectly converted mutable builders to records |
| src/Kook.Net.Core/Entities/Messages/Cards/Elements/*.cs | Converted immutable element types to records |
| src/Kook.Net.Core/Entities/Messages/Cards/Elements/Builders/*.cs | CRITICAL: Incorrectly converted mutable builders to records (except PlainTextElementBuilder) |
| src/Kook.Net.Core/Entities/Messages/Cards/CardBuilder.cs | CRITICAL: Incorrectly converted mutable builder to record |
| src/Kook.Net.Core/Entities/Messages/Cards/Card.cs | Converted immutable type to record |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// 用来构建 <see cref="SectionModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class VideoModuleBuilder : IModuleBuilder, IEquatable<VideoModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record VideoModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record VideoModuleBuilder : IModuleBuilder | |
| public class VideoModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="ImageGroupModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class ImageGroupModuleBuilder : IModuleBuilder, IEquatable<ImageGroupModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record ImageGroupModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record ImageGroupModuleBuilder : IModuleBuilder | |
| public class ImageGroupModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="FileModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class FileModuleBuilder : IModuleBuilder, IEquatable<FileModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record FileModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record FileModuleBuilder : IModuleBuilder | |
| public class FileModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="CountdownModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class CountdownModuleBuilder : IModuleBuilder, IEquatable<CountdownModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record CountdownModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record CountdownModuleBuilder : IModuleBuilder | |
| public class CountdownModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="ContainerModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class ContainerModuleBuilder : IModuleBuilder, IEquatable<ContainerModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record ContainerModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record ContainerModuleBuilder : IModuleBuilder | |
| public class ContainerModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="InviteModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class InviteModuleBuilder : IModuleBuilder, IEquatable<InviteModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record InviteModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record InviteModuleBuilder : IModuleBuilder | |
| public class InviteModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="DividerModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class DividerModuleBuilder : IModuleBuilder, IEquatable<DividerModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record DividerModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record DividerModuleBuilder : IModuleBuilder | |
| public class DividerModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="ContextModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class ContextModuleBuilder : IModuleBuilder, IEquatable<ContextModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record ContextModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record ContextModuleBuilder : IModuleBuilder | |
| public class ContextModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="ActionGroupModule"/> 模块的构建器。 | ||
| /// </summary> | ||
| public class ActionGroupModuleBuilder : IModuleBuilder, IEquatable<ActionGroupModuleBuilder>, IEquatable<IModuleBuilder> | ||
| public record ActionGroupModuleBuilder : IModuleBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record ActionGroupModuleBuilder : IModuleBuilder | |
| public class ActionGroupModuleBuilder : IModuleBuilder |
| /// 用来构建 <see cref="ParagraphStruct"/> 元素的构建器。 | ||
| /// </summary> | ||
| public class ParagraphStructBuilder : IElementBuilder, IEquatable<ParagraphStructBuilder>, IEquatable<IElementBuilder> | ||
| public record ParagraphStructBuilder : IElementBuilder |
There was a problem hiding this comment.
Converting mutable builder classes to records is problematic. Builders have mutable properties and use the fluent API pattern (returning this from methods). Records provide value-based equality which is inappropriate for mutable objects. Builders should remain as classes since they are designed to be mutated during their lifetime.
| public record ParagraphStructBuilder : IElementBuilder | |
| public class ParagraphStructBuilder : IElementBuilder |



No description provided.