Skip to content

Commit 67deb20

Browse files
committed
Replace enums with structs in Internal DTOs
1 parent 83f8ccc commit 67deb20

22 files changed

Lines changed: 497 additions & 376 deletions

Assets/Plugins/StreamChat/Core/Helpers/ILoadableFromExt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ internal static class ILoadableFromExt
99
{
1010
//StreamTodo: rename to TryCreateFromDto? It's misleading because it creates new instance which you need to replace
1111
public static TDomain TryLoadFromDto<TDto, TDomain>(this ILoadableFrom<TDto, TDomain> loadable, TDto dto)
12-
where TDomain : class, ILoadableFrom<TDto, TDomain>, new()
12+
where TDomain : ILoadableFrom<TDto, TDomain>, new()
1313
{
1414
if (dto == null)
1515
{
16-
return null;
16+
return default;
1717
}
1818

1919
return new TDomain().LoadFromDto(dto);
2020
}
2121

2222
public static TDomain UpdateFromDto<TDto, TDomain>(this ILoadableFrom<TDto, TDomain> loadable, TDto dto)
23-
where TDomain : class, ILoadableFrom<TDto, TDomain>, new()
23+
where TDomain : ILoadableFrom<TDto, TDomain>, new()
2424
{
2525
if (dto == null)
2626
{
27-
return null;
27+
return default;
2828
}
2929

3030
if (loadable == null)

Assets/Plugins/StreamChat/Core/InternalDTO/Models/AutomodBehaviourType.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,34 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum AutomodBehaviourType
17+
18+
public struct AutomodBehaviourType : System.IEquatable<AutomodBehaviourType>
1819
{
20+
public AutomodBehaviourType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"flag")]
21-
Flag = 0,
25+
public static readonly AutomodBehaviourType Flag = new AutomodBehaviourType("flag");
26+
public static readonly AutomodBehaviourType Block = new AutomodBehaviourType("block");
27+
public static readonly AutomodBehaviourType ShadowBlock = new AutomodBehaviourType("shadow_block");
2228

23-
[System.Runtime.Serialization.EnumMember(Value = @"block")]
24-
Block = 1,
29+
public override string ToString() => _value;
2530

26-
[System.Runtime.Serialization.EnumMember(Value = @"shadow_block")]
27-
Shadow_block = 2,
31+
public bool Equals(AutomodBehaviourType other) => _value == other._value;
2832

29-
}
33+
public override bool Equals(object obj) => obj is AutomodBehaviourType other && Equals(other);
3034

31-
}
35+
public override int GetHashCode() => _value.GetHashCode();
36+
37+
public static bool operator ==(AutomodBehaviourType left, AutomodBehaviourType right) => left.Equals(right);
3238

39+
public static bool operator !=(AutomodBehaviourType left, AutomodBehaviourType right) => !left.Equals(right);
40+
41+
public static implicit operator AutomodBehaviourType(string value) => new AutomodBehaviourType(value);
42+
43+
public static implicit operator string(AutomodBehaviourType type) => type._value;
44+
45+
private readonly string _value;
46+
}
47+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Models/AutomodType.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,34 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum AutomodType
17+
18+
public readonly struct AutomodType : System.IEquatable<AutomodType>
1819
{
20+
public AutomodType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"disabled")]
21-
Disabled = 0,
25+
public static readonly AutomodType Disabled = new AutomodType("disabled");
26+
public static readonly AutomodType Simple = new AutomodType("simple");
27+
public static readonly AutomodType AI = new AutomodType("AI");
2228

23-
[System.Runtime.Serialization.EnumMember(Value = @"simple")]
24-
Simple = 1,
29+
public override string ToString() => _value;
2530

26-
[System.Runtime.Serialization.EnumMember(Value = @"AI")]
27-
AI = 2,
31+
public bool Equals(AutomodType other) => _value == other._value;
2832

29-
}
33+
public override bool Equals(object obj) => obj is AutomodType other && Equals(other);
3034

31-
}
35+
public override int GetHashCode() => _value.GetHashCode();
36+
37+
public static bool operator ==(AutomodType left, AutomodType right) => left.Equals(right);
3238

39+
public static bool operator !=(AutomodType left, AutomodType right) => !left.Equals(right);
40+
41+
public static implicit operator AutomodType(string value) => new AutomodType(value);
42+
43+
public static implicit operator string(AutomodType type) => type._value;
44+
45+
private readonly string _value;
46+
}
47+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Models/BlockListOptionsBehavior.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,34 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum BlockListOptionsBehavior
17+
18+
internal struct BlockListOptionsBehavior : System.IEquatable<BlockListOptionsBehavior>
1819
{
20+
public BlockListOptionsBehavior(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"flag")]
21-
Flag = 0,
25+
public static readonly BlockListOptionsBehavior Flag = new BlockListOptionsBehavior("flag");
26+
public static readonly BlockListOptionsBehavior Block = new BlockListOptionsBehavior("block");
27+
public static readonly BlockListOptionsBehavior ShadowBlock = new BlockListOptionsBehavior("shadow_block");
2228

23-
[System.Runtime.Serialization.EnumMember(Value = @"block")]
24-
Block = 1,
29+
public override string ToString() => _value;
2530

26-
[System.Runtime.Serialization.EnumMember(Value = @"shadow_block")]
27-
Shadow_block = 2,
31+
public bool Equals(BlockListOptionsBehavior other) => _value == other._value;
2832

29-
}
33+
public override bool Equals(object obj) => obj is BlockListOptionsBehavior other && Equals(other);
3034

31-
}
35+
public override int GetHashCode() => _value.GetHashCode();
36+
37+
public static bool operator ==(BlockListOptionsBehavior left, BlockListOptionsBehavior right) => left.Equals(right);
3238

39+
public static bool operator !=(BlockListOptionsBehavior left, BlockListOptionsBehavior right) => !left.Equals(right);
40+
41+
public static implicit operator BlockListOptionsBehavior(string value) => new BlockListOptionsBehavior(value);
42+
43+
public static implicit operator string(BlockListOptionsBehavior type) => type._value;
44+
45+
private readonly string _value;
46+
}
47+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Models/ImageCropType.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,36 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum ImageCropType
17+
18+
public struct ImageCropType : System.IEquatable<ImageCropType>
1819
{
20+
public ImageCropType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"top")]
21-
Top = 0,
25+
public static readonly ImageCropType Top = new ImageCropType("top");
26+
public static readonly ImageCropType Bottom = new ImageCropType("bottom");
27+
public static readonly ImageCropType Left = new ImageCropType("left");
28+
public static readonly ImageCropType Right = new ImageCropType("right");
29+
public static readonly ImageCropType Center = new ImageCropType("center");
2230

23-
[System.Runtime.Serialization.EnumMember(Value = @"bottom")]
24-
Bottom = 1,
31+
public override string ToString() => _value;
2532

26-
[System.Runtime.Serialization.EnumMember(Value = @"left")]
27-
Left = 2,
33+
public bool Equals(ImageCropType other) => _value == other._value;
2834

29-
[System.Runtime.Serialization.EnumMember(Value = @"right")]
30-
Right = 3,
35+
public override bool Equals(object obj) => obj is ImageCropType other && Equals(other);
3136

32-
[System.Runtime.Serialization.EnumMember(Value = @"center")]
33-
Center = 4,
37+
public override int GetHashCode() => _value.GetHashCode();
3438

35-
}
39+
public static bool operator ==(ImageCropType left, ImageCropType right) => left.Equals(right);
3640

37-
}
41+
public static bool operator !=(ImageCropType left, ImageCropType right) => !left.Equals(right);
3842

43+
public static implicit operator ImageCropType(string value) => new ImageCropType(value);
44+
45+
public static implicit operator string(ImageCropType type) => type._value;
46+
47+
private readonly string _value;
48+
}
49+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Models/ImageResizeType.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum ImageResizeType
17+
18+
public struct ImageResizeType : System.IEquatable<ImageResizeType>
1819
{
20+
public ImageResizeType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"clip")]
21-
Clip = 0,
25+
public static readonly ImageResizeType Clip = new ImageResizeType("clip");
26+
public static readonly ImageResizeType Crop = new ImageResizeType("crop");
27+
public static readonly ImageResizeType Scale = new ImageResizeType("scale");
28+
public static readonly ImageResizeType Fill = new ImageResizeType("fill");
2229

23-
[System.Runtime.Serialization.EnumMember(Value = @"crop")]
24-
Crop = 1,
30+
public override string ToString() => _value;
2531

26-
[System.Runtime.Serialization.EnumMember(Value = @"scale")]
27-
Scale = 2,
32+
public bool Equals(ImageResizeType other) => _value == other._value;
2833

29-
[System.Runtime.Serialization.EnumMember(Value = @"fill")]
30-
Fill = 3,
34+
public override bool Equals(object obj) => obj is ImageResizeType other && Equals(other);
3135

32-
}
36+
public override int GetHashCode() => _value.GetHashCode();
3337

34-
}
38+
public static bool operator ==(ImageResizeType left, ImageResizeType right) => left.Equals(right);
39+
40+
public static bool operator !=(ImageResizeType left, ImageResizeType right) => !left.Equals(right);
3541

42+
public static implicit operator ImageResizeType(string value) => new ImageResizeType(value);
43+
44+
public static implicit operator string(ImageResizeType type) => type._value;
45+
46+
private readonly string _value;
47+
}
48+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Models/MessageType.cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,37 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum MessageType
17+
18+
public struct MessageType : System.IEquatable<MessageType>
1819
{
20+
public MessageType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"regular")]
21-
Regular = 0,
25+
public static readonly MessageType Regular = new MessageType("regular");
26+
public static readonly MessageType Ephemeral = new MessageType("ephemeral");
27+
public static readonly MessageType Error = new MessageType("error");
28+
public static readonly MessageType Reply = new MessageType("reply");
29+
public static readonly MessageType System = new MessageType("system");
30+
public static readonly MessageType Deleted = new MessageType("deleted");
2231

23-
[System.Runtime.Serialization.EnumMember(Value = @"ephemeral")]
24-
Ephemeral = 1,
32+
public override string ToString() => _value;
2533

26-
[System.Runtime.Serialization.EnumMember(Value = @"error")]
27-
Error = 2,
34+
public bool Equals(MessageType other) => _value == other._value;
2835

29-
[System.Runtime.Serialization.EnumMember(Value = @"reply")]
30-
Reply = 3,
36+
public override bool Equals(object obj) => obj is MessageType other && Equals(other);
3137

32-
[System.Runtime.Serialization.EnumMember(Value = @"system")]
33-
System = 4,
38+
public override int GetHashCode() => _value.GetHashCode();
3439

35-
[System.Runtime.Serialization.EnumMember(Value = @"deleted")]
36-
Deleted = 5,
40+
public static bool operator ==(MessageType left, MessageType right) => left.Equals(right);
3741

38-
}
42+
public static bool operator !=(MessageType left, MessageType right) => !left.Equals(right);
3943

40-
}
44+
public static implicit operator MessageType(string value) => new MessageType(value);
4145

46+
public static implicit operator string(MessageType type) => type._value;
47+
48+
private readonly string _value;
49+
}
50+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Models/PushProviderType.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,35 @@ namespace StreamChat.Core.InternalDTO.Models
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum PushProviderType
17+
18+
public struct PushProviderType : System.IEquatable<PushProviderType>
1819
{
20+
public PushProviderType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"firebase")]
21-
Firebase = 0,
25+
public static readonly PushProviderType Firebase = new PushProviderType("firebase");
26+
public static readonly PushProviderType Apn = new PushProviderType("apn");
27+
public static readonly PushProviderType Huawei = new PushProviderType("huawei");
28+
public static readonly PushProviderType Xiaomi = new PushProviderType("xiaomi");
2229

23-
[System.Runtime.Serialization.EnumMember(Value = @"apn")]
24-
Apn = 1,
30+
public override string ToString() => _value;
2531

26-
[System.Runtime.Serialization.EnumMember(Value = @"huawei")]
27-
Huawei = 2,
32+
public bool Equals(PushProviderType other) => _value == other._value;
2833

29-
[System.Runtime.Serialization.EnumMember(Value = @"xiaomi")]
30-
Xiaomi = 3,
34+
public override bool Equals(object obj) => obj is PushProviderType other && Equals(other);
3135

32-
}
36+
public override int GetHashCode() => _value.GetHashCode();
3337

34-
}
38+
public static bool operator ==(PushProviderType left, PushProviderType right) => left.Equals(right);
39+
40+
public static bool operator !=(PushProviderType left, PushProviderType right) => !left.Equals(right);
3541

42+
public static implicit operator PushProviderType(string value) => new PushProviderType(value);
43+
44+
public static implicit operator string(PushProviderType type) => type._value;
45+
46+
private readonly string _value;
47+
}
48+
}

Assets/Plugins/StreamChat/Core/InternalDTO/Requests/CreateCallRequestType.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,33 @@ namespace StreamChat.Core.InternalDTO.Requests
1414
using System = global::System;
1515

1616
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))")]
17-
public enum CreateCallRequestType
17+
18+
internal struct CreateCallRequestType : System.IEquatable<CreateCallRequestType>
1819
{
20+
public CreateCallRequestType(string value)
21+
{
22+
_value = value ?? throw new System.ArgumentNullException(nameof(value));
23+
}
1924

20-
[System.Runtime.Serialization.EnumMember(Value = @"audio")]
21-
Audio = 0,
25+
public static readonly CreateCallRequestType Audio = new CreateCallRequestType("audio");
26+
public static readonly CreateCallRequestType Video = new CreateCallRequestType("video");
2227

23-
[System.Runtime.Serialization.EnumMember(Value = @"video")]
24-
Video = 1,
28+
public override string ToString() => _value;
2529

26-
}
30+
public bool Equals(CreateCallRequestType other) => _value == other._value;
2731

28-
}
32+
public override bool Equals(object obj) => obj is CreateCallRequestType other && Equals(other);
33+
34+
public override int GetHashCode() => _value.GetHashCode();
35+
36+
public static bool operator ==(CreateCallRequestType left, CreateCallRequestType right) => left.Equals(right);
2937

38+
public static bool operator !=(CreateCallRequestType left, CreateCallRequestType right) => !left.Equals(right);
39+
40+
public static implicit operator CreateCallRequestType(string value) => new CreateCallRequestType(value);
41+
42+
public static implicit operator string(CreateCallRequestType type) => type._value;
43+
44+
private readonly string _value;
45+
}
46+
}

0 commit comments

Comments
 (0)