Skip to content

Commit fb6057d

Browse files
committed
Code Analysis - CA2227
Collection properties should be read only https://docs.microsoft.com/en-gb/visualstudio/code-quality/ca2227 Suppress FxCopAnalyzers warning CA2227 as System.Text.Json.JsonSerializer.Deserialize in .NET Core 3.1 cannot deserialise to read-only properties. There are two related issues that will allow System.Text.Json.JsonSerializer.Deserialize to deserialise to read-only properties in .NET Core 5.0: 1) Pull Request that includes support for non-public accessors: dotnet/runtime#34675 2) Issue regarding, among other things, adding to collections during deserialisation if the collection property has no setter: dotnet/runtime#30258
1 parent 5a1c2e1 commit fb6057d

20 files changed

+57
-0
lines changed

OBSWebSocketLibrary/Models/Events/SceneItems.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class SourceOrderChanged : EventBase
1010
[JsonPropertyName("scene-name")]
1111
public string SceneName { get; set; }
1212
[JsonPropertyName("scene-items")]
13+
#pragma warning disable CA2227 // Collection properties should be read only
1314
public IList<TypeDefs.ObsEventSceneItem> SceneItems { get; set; }
15+
#pragma warning restore CA2227 // Collection properties should be read only
1416
}
1517

1618
public class SceneItemAdded : EventBase

OBSWebSocketLibrary/Models/Events/Scenes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class SwitchScenes : EventBase
1010
[JsonPropertyName("scene-name")]
1111
public string SceneName { get; set; }
1212
[JsonPropertyName("sources")]
13+
#pragma warning disable CA2227 // Collection properties should be read only
1314
public IList<TypeDefs.SceneItem> Sources { get; set; }
15+
#pragma warning restore CA2227 // Collection properties should be read only
1416
}
1517

1618
public class ScenesChanged : EventBase

OBSWebSocketLibrary/Models/Events/Sources.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public class SourceAudioMixersChanged : EventBase
5858
[JsonPropertyName("sourceName")]
5959
public string SourceName { get; set; }
6060
[JsonPropertyName("mixers")]
61+
#pragma warning disable CA2227 // Collection properties should be read only
6162
public IList<TypeDefs.ObsMixer> Mixers { get; set; }
63+
#pragma warning restore CA2227 // Collection properties should be read only
6264
[JsonPropertyName("hexMixersValue")]
6365
public string HexMixersValue { get; set; }
6466
}
@@ -110,6 +112,8 @@ public class SourceFiltersReordered : EventBase
110112
[JsonPropertyName("sourceName")]
111113
public string SourceName { get; set; }
112114
[JsonPropertyName("filters")]
115+
#pragma warning disable CA2227 // Collection properties should be read only
113116
public IList<TypeDefs.ObsFilter> Filters { get; set; }
117+
#pragma warning restore CA2227 // Collection properties should be read only
114118
}
115119
}

OBSWebSocketLibrary/Models/Events/StudioMode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class PreviewSceneChanged : EventBase
1010
[JsonPropertyName("scene-name")]
1111
public string SceneName { get; set; }
1212
[JsonPropertyName("GetCurrentScene")]
13+
#pragma warning disable CA2227 // Collection properties should be read only
1314
public IList<TypeDefs.SceneItem> GetCurrentScene { get; set; }
15+
#pragma warning restore CA2227 // Collection properties should be read only
1416
}
1517

1618
public class StudioModeSwitched : EventBase

OBSWebSocketLibrary/Models/RequestReplies/Outputs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ namespace OBSWebSocketLibrary.Models.RequestReplies
88
public class ListOutputs : RequestReplyBase
99
{
1010
[JsonPropertyName("outputs")]
11+
#pragma warning disable CA2227 // Collection properties should be read only
1112
public IList<TypeDefs.Output> Outputs { get; set; }
13+
#pragma warning restore CA2227 // Collection properties should be read only
1214
}
1315

1416
public class GetOutputInfo : RequestReplyBase

OBSWebSocketLibrary/Models/RequestReplies/Profiles.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class GetCurrentProfile : RequestReplyBase
1919
public class ListProfiles : RequestReplyBase
2020
{
2121
[JsonPropertyName("profiles")]
22+
#pragma warning disable CA2227 // Collection properties should be read only
2223
public IList<OBSWebSocketLibrary.Models.TypeDefs.ObsProfile> Profiles { get; set; }
24+
#pragma warning restore CA2227 // Collection properties should be read only
2325
}
2426
}

OBSWebSocketLibrary/Models/RequestReplies/SceneCollections.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public class GetCurrentSceneCollection : RequestReplyBase
1818
public class ListSceneCollections : RequestReplyBase
1919
{
2020
[JsonPropertyName("scene-collections")]
21+
#pragma warning disable CA2227 // Collection properties should be read only
2122
public IList<string> SceneCollections { get; set; }
23+
#pragma warning restore CA2227 // Collection properties should be read only
2224
}
2325
}

OBSWebSocketLibrary/Models/RequestReplies/SceneItems.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public class GetSceneItemProperties : RequestReplyBase
4040
[JsonPropertyName("parentGroupName")]
4141
public string ParentGroupName { get; set; }
4242
[JsonPropertyName("groupChildren")]
43+
#pragma warning disable CA2227 // Collection properties should be read only
4344
public IList<TypeDefs.SceneItemTransform> GroupChildren { get; set; }
45+
#pragma warning restore CA2227 // Collection properties should be read only
4446
}
4547

4648
public class SetSceneItemProperties : RequestReplyBase

OBSWebSocketLibrary/Models/RequestReplies/Scenes.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Runtime.Serialization;
34
using System.Text;
45
using System.Text.Json.Serialization;
56

@@ -14,15 +15,19 @@ public class GetCurrentScene : RequestReplyBase
1415
[JsonPropertyName("name")]
1516
public string Name { get; set; }
1617
[JsonPropertyName("sources")]
18+
#pragma warning disable CA2227 // Collection properties should be read only
1719
public IList<TypeDefs.SceneItem> Sources { get; set; }
20+
#pragma warning restore CA2227 // Collection properties should be read only
1821
}
1922

2023
public class GetSceneList : RequestReplyBase
2124
{
2225
[JsonPropertyName("current-scene")]
2326
public string CurrentScene { get; set; }
2427
[JsonPropertyName("scenes")]
28+
#pragma warning disable CA2227 // Collection properties should be read only
2529
public IList<TypeDefs.Scene> Scenes { get; set; }
30+
#pragma warning restore CA2227 // Collection properties should be read only
2631
}
2732

2833
public class ReorderSceneItems : RequestReplyBase

OBSWebSocketLibrary/Models/RequestReplies/Sources.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ namespace OBSWebSocketLibrary.Models.RequestReplies
99
public class GetSourcesList : RequestReplyBase
1010
{
1111
[JsonPropertyName("sources")]
12+
#pragma warning disable CA2227 // Collection properties should be read only
1213
public IList<TypeDefs.ObsReplySource> Sources { get; set; }
14+
#pragma warning restore CA2227 // Collection properties should be read only
1315
}
1416

1517
public class GetSourceTypesList : RequestReplyBase
1618
{
1719
[JsonPropertyName("types")]
20+
#pragma warning disable CA2227 // Collection properties should be read only
1821
public IList<TypeDefs.ObsReplyType> Types { get; set; }
22+
#pragma warning restore CA2227 // Collection properties should be read only
1923
}
2024

2125
public class GetVolume : RequestReplyBase
@@ -217,7 +221,9 @@ public class GetSpecialSources : RequestReplyBase
217221
public class GetSourceFilters : RequestReplyBase
218222
{
219223
[JsonPropertyName("filters")]
224+
#pragma warning disable CA2227 // Collection properties should be read only
220225
public IList<TypeDefs.ObsReplyFilter> Filters { get; set; }
226+
#pragma warning restore CA2227 // Collection properties should be read only
221227
}
222228

223229
public class GetSourceFilterInfo : RequestReplyBase

OBSWebSocketLibrary/Models/RequestReplies/StudioMode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public class GetPreviewScene : RequestReplyBase
1414
[JsonPropertyName("name")]
1515
public string Name { get; set; }
1616
[JsonPropertyName("sources")]
17+
#pragma warning disable CA2227 // Collection properties should be read only
1718
public IList<TypeDefs.SceneItem> Sources { get; set; }
19+
#pragma warning restore CA2227 // Collection properties should be read only
1820
}
1921

2022
public class SetPreviewScene : RequestReplyBase

OBSWebSocketLibrary/Models/RequestReplies/Transitions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ public class GetTransitionList : RequestReplyBase
1010
[JsonPropertyName("current-transition")]
1111
public string CurrentTransition { get; set; }
1212
[JsonPropertyName("transitions")]
13+
#pragma warning disable CA2227 // Collection properties should be read only
1314
public IList<TypeDefs.ObsTransitionName> Transitions { get; set; }
15+
#pragma warning restore CA2227 // Collection properties should be read only
1416
}
1517

1618
public class GetCurrentTransition : RequestReplyBase

OBSWebSocketLibrary/Models/Requests/Scenes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public class ReorderSceneItems : RequestBase
2525
[JsonPropertyName("scene")]
2626
public string Scene { get; set; }
2727
[JsonPropertyName("items")]
28+
#pragma warning disable CA2227 // Collection properties should be read only
2829
public IList<TypeDefs.ItemObject> Items { get; set; }
30+
#pragma warning restore CA2227 // Collection properties should be read only
2931
}
3032

3133
public class SetSceneTransitionOverride : RequestBase

OBSWebSocketLibrary/Models/TypeDefs/Scene.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class Scene
1111
[JsonPropertyName("name")]
1212
public string Name { get; set; }
1313
[JsonPropertyName("sources")]
14+
#pragma warning disable CA2227 // Collection properties should be read only
1415
public ObservableCollection<SceneItem> Sources { get; set; }
16+
#pragma warning restore CA2227 // Collection properties should be read only
1517
}
1618
}

OBSWebSocketLibrary/Models/TypeDefs/SceneItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public double Volume
8787
[JsonPropertyName("parentGroupName")]
8888
public string ParentGroupName { get; set; }
8989
[JsonPropertyName("groupChildren")]
90+
#pragma warning disable CA2227 // Collection properties should be read only
9091
public ObservableCollection<SceneItem> GroupChildren { get; set; }
92+
#pragma warning restore CA2227 // Collection properties should be read only
9193
[JsonIgnore]
9294
public SourceTypes.BaseType Source
9395
{

OBSWebSocketLibrary/Models/TypeDefs/SceneItemTransform.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public class SceneItemTransform
3232
[JsonPropertyName("parentGroupName")]
3333
public string ParentGroupName { get; set; }
3434
[JsonPropertyName("groupChildren")]
35+
#pragma warning disable CA2227 // Collection properties should be read only
3536
public IList<SceneItemTransform> GroupChildren { get; set; }
37+
#pragma warning restore CA2227 // Collection properties should be read only
3638

3739
public static implicit operator SceneItemTransform(RequestReplies.GetSceneItemProperties v)
3840
{

OBSWebSocketLibrary/Models/TypeDefs/SourceTypes/BaseType.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public string MonitorType
7878
}
7979
}
8080
[JsonIgnore]
81+
#pragma warning disable CA2227 // Collection properties should be read only
8182
public IList<ObsMixer> Mixers
83+
#pragma warning restore CA2227 // Collection properties should be read only
8284
{
8385
get { return mixers; }
8486
set
@@ -98,7 +100,9 @@ public string HexMixersValue
98100
}
99101
}
100102
[JsonIgnore]
103+
#pragma warning disable CA2227 // Collection properties should be read only
101104
public ObservableCollection<FilterTypes.BaseFilter> Filters { get; set; }
105+
#pragma warning restore CA2227 // Collection properties should be read only
102106

103107
[JsonIgnore]
104108
public TypeDefs.ObsReplyType Type { get; set; }

OBSWebSocketLibrary/Models/TypeDefs/SourceTypes/Composite.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public class Scene : BaseType
1313
[JsonPropertyName("id_counter")]
1414
public int IdCounter { get; set; }
1515
[JsonPropertyName("items")]
16+
#pragma warning disable CA2227 // Collection properties should be read only
1617
public IList<ObsSceneItem> Items { get; set; }
18+
#pragma warning restore CA2227 // Collection properties should be read only
1719
}
1820

1921
public class Group : BaseType
@@ -27,6 +29,8 @@ public class Group : BaseType
2729
[JsonPropertyName("id_counter")]
2830
public int IdCounter { get; set; }
2931
[JsonPropertyName("items")]
32+
#pragma warning disable CA2227 // Collection properties should be read only
3033
public IList<ObsSceneItem> Items { get; set; }
34+
#pragma warning restore CA2227 // Collection properties should be read only
3135
}
3236
}

OBSWebSocketLibrary/Models/TypeDefs/SourceTypes/DependencyProperties.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public bool HasVideoInterface
8989
get { return !String.IsNullOrEmpty(VideoDeviceId); }
9090
}
9191

92+
#pragma warning disable CA2227 // Collection properties should be read only
9293
public IList<string> FilePaths
94+
#pragma warning restore CA2227 // Collection properties should be read only
9395
{
9496
get { return filePaths; }
9597
set
@@ -103,7 +105,9 @@ public bool HasFiles
103105
get { return FilePaths != null && FilePaths.Count != 0; }
104106
}
105107

108+
#pragma warning disable CA2227 // Collection properties should be read only
106109
public IList<string> Uris
110+
#pragma warning restore CA2227 // Collection properties should be read only
107111
{
108112
get { return uris; }
109113
set

OBSWebSocketLibrary/Models/TypeDefs/SourceTypes/Video.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public class ColorSourceV2 : BaseType
3030
public class Slideshow : BaseType
3131
{
3232
[JsonPropertyName("files")]
33+
#pragma warning disable CA2227 // Collection properties should be read only
3334
public IList<ObsFile> Files { get; set; }
35+
#pragma warning restore CA2227 // Collection properties should be read only
3436
[JsonPropertyName("playback_behavior")]
3537
public string PlaybackBehavior { get; set; }
3638
[JsonPropertyName("slide_time")]
@@ -172,7 +174,9 @@ public class VlcSource : BaseType
172174
[JsonPropertyName("playback_behavior")]
173175
public string PlaybackBehavior { get; set; }
174176
[JsonPropertyName("playlist")]
177+
#pragma warning disable CA2227 // Collection properties should be read only
175178
public IList<VlcPlaylistItem> Playlist { get; set; }
179+
#pragma warning restore CA2227 // Collection properties should be read only
176180
[JsonPropertyName("shuffle")]
177181
public bool Shuffle { get; set; }
178182
[JsonPropertyName("subtitle")]

0 commit comments

Comments
 (0)