Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit 5be9642

Browse files
committed
chore(CodeContracts): remove CodeContract support
CodeContracts is not supported anymore in the later Visual Studios version. Reverted Contracts to if() statements.
1 parent 5229f34 commit 5be9642

22 files changed

+51
-76
lines changed

Implementation/ChestManager.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4-
using System.Diagnostics.Contracts;
54
using System.Linq;
65
using System.Text;
76
using System.Threading.Tasks;
@@ -30,7 +29,7 @@ public class ChestManager {
3029
public Configuration Config {
3130
get { return this.config; }
3231
set {
33-
Contract.Requires<ArgumentNullException>(value != null);
32+
if (value == null) throw new ArgumentNullException();
3433
this.config = value;
3534
}
3635
}
@@ -62,10 +61,10 @@ public bool SetUpRefillChest(
6261
TSPlayer player, DPoint tileLocation, TimeSpan? refillTime, bool? oneLootPerPlayer = null, int? lootLimit = null,
6362
bool? autoLock = null, bool? autoEmpty = null, bool fairLoot = false, bool checkPermissions = false
6463
) {
65-
Contract.Requires<ArgumentNullException>(player != null);
66-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
67-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
68-
Contract.Requires<ArgumentOutOfRangeException>(lootLimit == null || lootLimit >= -1);
64+
if (player == null) throw new ArgumentNullException();
65+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
66+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
67+
if (!(lootLimit == null || lootLimit >= -1)) throw new ArgumentOutOfRangeException();
6968

7069
ITile tile = TerrariaUtils.Tiles[tileLocation];
7170
if (tile.type != TileID.Containers && tile.type != TileID.Containers2 && tile.type != TileID.Dressers)
@@ -157,10 +156,10 @@ public bool SetUpRefillChest(
157156
}
158157

159158
public void SetUpBankChest(TSPlayer player, DPoint tileLocation, int bankChestIndex, bool checkPermissions = false) {
160-
Contract.Requires<ArgumentNullException>(player != null);
161-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
162-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
163-
Contract.Requires<ArgumentOutOfRangeException>(bankChestIndex >= 1, "bankChestIndex");
159+
if (player == null) throw new ArgumentNullException();
160+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
161+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
162+
if (!(bankChestIndex >= 1)) throw new ArgumentOutOfRangeException("bankChestIndex");
164163

165164
ITile tile = TerrariaUtils.Tiles[tileLocation];
166165
if (tile.type != TileID.Containers && tile.type != TileID.Containers2 && tile.type != TileID.Dressers)
@@ -229,11 +228,11 @@ public void SetUpBankChest(TSPlayer player, DPoint tileLocation, int bankChestIn
229228
}
230229

231230
public void SetUpTradeChest(TSPlayer player, DPoint tileLocation, int sellAmount, int sellItemId, int payAmount, object payItemIdOrGroup, int lootLimit = 0, bool checkPermissions = false) {
232-
Contract.Requires<ArgumentNullException>(player != null);
233-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
234-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
235-
Contract.Requires<ArgumentOutOfRangeException>(sellAmount > 0, "sellAmount");
236-
Contract.Requires<ArgumentOutOfRangeException>(payAmount > 0, "payAmount");
231+
if (player == null) throw new ArgumentNullException();
232+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
233+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
234+
if (!(sellAmount > 0)) throw new ArgumentOutOfRangeException("sellAmount");
235+
if (!(payAmount > 0)) throw new ArgumentOutOfRangeException("payAmount");
237236

238237
Item itemInfo = new Item();
239238
itemInfo.netDefaults(sellItemId);
@@ -315,7 +314,8 @@ public bool TryRefillChest(IChest chest, RefillChestMetadata refillChestData) {
315314
}
316315

317316
public IChest PlaceChest(ushort tileType, int style, DPoint placeLocation) {
318-
Contract.Requires<ArgumentException>(tileType == TileID.Containers || tileType == TileID.Containers2 || tileType == TileID.Dressers);
317+
if (!(tileType == TileID.Containers || tileType == TileID.Containers2 || tileType == TileID.Dressers))
318+
throw new ArgumentException();
319319

320320
IChest chest;
321321
bool isDresser = (tileType == TileID.Dressers);

Implementation/PluginCooperationHandler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Data;
3-
using System.Diagnostics.Contracts;
43
using System.IO;
54
using DPoint = System.Drawing.Point;
65

@@ -34,8 +33,8 @@ private enum InfiniteChestsChestFlags {
3433

3534

3635
public PluginCooperationHandler(PluginTrace pluginTrace, Configuration config, ChestManager chestManager) {
37-
Contract.Requires<ArgumentNullException>(pluginTrace != null);
38-
Contract.Requires<ArgumentNullException>(config != null);
36+
if (pluginTrace == null) throw new ArgumentNullException();
37+
if (config == null) throw new ArgumentNullException();
3938

4039
this.PluginTrace = pluginTrace;
4140
this.Config = config;
@@ -48,7 +47,7 @@ public PluginCooperationHandler(PluginTrace pluginTrace, Configuration config, C
4847
public void InfiniteChests_ChestDataImport(
4948
ChestManager chestManager, ProtectionManager protectionManager, out int importedChests, out int protectFailures
5049
) {
51-
Contract.Assert(this.ChestManager != null);
50+
//Contract.Assert(this.ChestManager != null);
5251

5352
importedChests = 0;
5453
protectFailures = 0;

Implementation/ProtectionManager.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.Contracts;
43
using System.Collections.ObjectModel;
54
using System.Linq;
65
using OTAPI.Tile;
@@ -24,7 +23,7 @@ public class ProtectionManager {
2423
public Configuration Config {
2524
get { return this.config; }
2625
set {
27-
Contract.Requires<ArgumentNullException>(value != null);
26+
if (value == null) throw new ArgumentNullException();
2827
this.config = value;
2928
}
3029
}
@@ -248,9 +247,9 @@ public ProtectionEntry CreateProtection(
248247
TSPlayer player, DPoint tileLocation, bool checkIfBlockTypeProtectableByConfig = true,
249248
bool checkTShockBuildAndRegionAccess = true, bool checkLimits = true
250249
) {
251-
Contract.Requires<ArgumentNullException>(player != null);
252-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
253-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
250+
if (player == null) throw new ArgumentNullException();
251+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
252+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
254253

255254
ITile tile = TerrariaUtils.Tiles[tileLocation];
256255
int blockType = tile.type;
@@ -288,7 +287,7 @@ public ProtectionEntry CreateProtection(
288287
}
289288

290289
public void RemoveProtection(TSPlayer player, DPoint tileLocation, bool checkIfBlockTypeDeprotectableByConfig = true) {
291-
Contract.Requires<ArgumentNullException>(player != null);
290+
if (player == null) throw new ArgumentNullException();
292291

293292
bool canDeprotectEverything = player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission);
294293
if (TerrariaUtils.Tiles.IsValidCoord(tileLocation)) {
@@ -321,9 +320,9 @@ public void RemoveProtection(TSPlayer player, DPoint tileLocation, bool checkIfB
321320
}
322321

323322
public void ProtectionShareAll(TSPlayer player, DPoint tileLocation, bool shareOrUnshare, bool checkPermissions = false) {
324-
Contract.Requires<ArgumentNullException>(player != null);
325-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
326-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
323+
if (player == null) throw new ArgumentNullException();
324+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
325+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
327326

328327
ProtectionEntry protection;
329328
try {
@@ -346,9 +345,9 @@ public void ProtectionShareAll(TSPlayer player, DPoint tileLocation, bool shareO
346345
public void ProtectionShareUser(
347346
TSPlayer player, DPoint tileLocation, int targetUserId, bool shareOrUnshare = true, bool checkPermissions = false
348347
) {
349-
Contract.Requires<ArgumentNullException>(player != null);
350-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
351-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
348+
if (player == null) throw new ArgumentNullException();
349+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
350+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
352351

353352
ProtectionEntry protection;
354353
try {
@@ -383,10 +382,10 @@ public void ProtectionShareUser(
383382
public void ProtectionShareGroup(
384383
TSPlayer player, DPoint tileLocation, string targetGroupName, bool shareOrUnshare = true, bool checkPermissions = false
385384
) {
386-
Contract.Requires<ArgumentNullException>(player != null);
387-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation] != null, "tileLocation");
388-
Contract.Requires<ArgumentException>(TerrariaUtils.Tiles[tileLocation].active(), "tileLocation");
389-
Contract.Requires<ArgumentNullException>(targetGroupName != null);
385+
if (player == null) throw new ArgumentNullException();
386+
if (!(TerrariaUtils.Tiles[tileLocation] != null)) throw new ArgumentException("tileLocation");
387+
if (!(TerrariaUtils.Tiles[tileLocation].active())) throw new ArgumentException("tileLocation");
388+
if (targetGroupName == null) throw new ArgumentNullException();
390389

391390
ProtectionEntry protection;
392391
try {

Implementation/ProtectorPlugin.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.ComponentModel;
44
using System.Diagnostics;
5-
using System.Diagnostics.Contracts;
65
using System.IO;
76
using System.Reflection;
87
using System.Threading;

Implementation/ServerMetadataHandler.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics.Contracts;
43
using System.Text;
54
using System.Threading.Tasks;
65

@@ -32,7 +31,7 @@ public override void EnsureDataStructure() {
3231
}
3332

3433
public Task<int> EnqueueGetBankChestCount() {
35-
Contract.Requires<ObjectDisposedException>(!base.IsDisposed);
34+
if (base.IsDisposed) throw new ObjectDisposedException(this.ToString());
3635

3736
lock (this.workQueueLock) {
3837
return this.WorkQueue.EnqueueTask(() => {
@@ -53,8 +52,8 @@ private int GetBankChestCount() {
5352
}
5453

5554
public Task<BankChestMetadata> EnqueueGetBankChestMetadata(BankChestDataKey key) {
56-
Contract.Requires<ObjectDisposedException>(!this.IsDisposed);
57-
Contract.Requires<ArgumentException>(key != BankChestDataKey.Invalid);
55+
if (base.IsDisposed) throw new ObjectDisposedException(this.ToString());
56+
if (!(key != BankChestDataKey.Invalid)) throw new ArgumentException();
5857

5958
lock (this.workQueueLock) {
6059
return this.WorkQueue.EnqueueTask((keyLocal) => {
@@ -85,7 +84,7 @@ private BankChestMetadata GetBankChestMetadata(BankChestDataKey key) {
8584
}
8685

8786
public Task EnqueueAddOrUpdateBankChest(BankChestDataKey key, BankChestMetadata bankChest) {
88-
Contract.Requires<ObjectDisposedException>(!this.IsDisposed);
87+
if (base.IsDisposed) throw new ObjectDisposedException(this.ToString());
8988

9089
lock (this.workQueueLock) {
9190
return this.WorkQueue.EnqueueTask(() => {
@@ -120,7 +119,7 @@ private void AddOrUpdateBankChest(BankChestDataKey key, BankChestMetadata bankCh
120119
}
121120

122121
public Task EnqueueUpdateBankChestItem(BankChestDataKey key, int slotIndex, ItemData newItem) {
123-
Contract.Requires<ObjectDisposedException>(!this.IsDisposed);
122+
if (base.IsDisposed) throw new ObjectDisposedException(this.ToString());
124123

125124
lock (this.workQueueLock) {
126125
return this.WorkQueue.EnqueueTask(() => {
@@ -139,7 +138,7 @@ private void UpdateBankChestItem(BankChestDataKey key, int slotIndex, ItemData n
139138
}
140139

141140
public Task EnqueueDeleteBankChestsOfUser(int userId) {
142-
Contract.Requires<ObjectDisposedException>(!this.IsDisposed);
141+
if (base.IsDisposed) throw new ObjectDisposedException(this.ToString());
143142

144143
lock (this.workQueueLock) {
145144
return this.WorkQueue.EnqueueTask((userIdLocal) => {

Implementation/UserInteractionHandler.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Collections.ObjectModel;
5-
using System.Diagnostics.Contracts;
65
using System.Globalization;
76
using System.IO;
87
using System.Linq;
@@ -38,14 +37,14 @@ public UserInteractionHandler(
3837
WorldMetadata worldMetadata, ProtectionManager protectionManager, ChestManager chestManager,
3938
PluginCooperationHandler pluginCooperationHandler, Func<Configuration> reloadConfigurationCallback
4039
): base(trace) {
41-
Contract.Requires<ArgumentNullException>(trace != null);
42-
Contract.Requires<ArgumentException>(!pluginInfo.Equals(PluginInfo.Empty));
43-
Contract.Requires<ArgumentNullException>(config != null);
44-
Contract.Requires<ArgumentNullException>(serverMetadataHandler != null);
45-
Contract.Requires<ArgumentNullException>(worldMetadata != null);
46-
Contract.Requires<ArgumentNullException>(protectionManager != null);
47-
Contract.Requires<ArgumentNullException>(pluginCooperationHandler != null);
48-
Contract.Requires<ArgumentNullException>(reloadConfigurationCallback != null);
40+
if (trace == null) throw new ArgumentNullException();
41+
if (!(!pluginInfo.Equals(PluginInfo.Empty))) throw new ArgumentException();
42+
if (config == null) throw new ArgumentNullException();
43+
if (serverMetadataHandler == null) throw new ArgumentNullException();
44+
if (worldMetadata == null) throw new ArgumentNullException();
45+
if (protectionManager == null) throw new ArgumentNullException();
46+
if (pluginCooperationHandler == null) throw new ArgumentNullException();
47+
if (reloadConfigurationCallback == null) throw new ArgumentNullException();
4948

5049
this.PluginInfo = pluginInfo;
5150
this.Config = config;
@@ -2879,7 +2878,7 @@ public virtual bool HandleChestModifySlot(TSPlayer player, int chestIndex, int s
28792878
}
28802879

28812880
if (refillChest.OneLootPerPlayer || refillChest.RemainingLoots > 0) {
2882-
Contract.Assert(refillChest.Looters != null);
2881+
//Contract.Assert(refillChest.Looters != null);
28832882
if (!refillChest.Looters.Contains(player.Account.ID)) {
28842883
refillChest.Looters.Add(player.Account.ID);
28852884

Implementation/WorldMetadataHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Diagnostics.Contracts;
53
using OTAPI.Tile;
64
using DPoint = System.Drawing.Point;
75

Implementation/_Data/BankChestDataKey.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics.Contracts;
32

43
using Newtonsoft.Json;
54

Implementation/_Data/ChestAdapter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4-
using System.Diagnostics.Contracts;
54
using System.Linq;
65
using System.Runtime.Remoting.Messaging;
76
using System.Text;
@@ -26,7 +25,7 @@ public string Name {
2625
public IList<ItemData> Items { get; }
2726

2827
public ChestAdapter(int chestIndex, Chest tChest) {
29-
Contract.Requires<ArgumentNullException>(tChest != null);
28+
if (tChest == null) throw new ArgumentNullException();
3029

3130
this.Index = chestIndex;
3231
this.tChest = tChest;

Implementation/_Data/Config/Configuration.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Diagnostics.Contracts;
53
using System.IO;
64
using System.Linq;
75
using System.Xml;

0 commit comments

Comments
 (0)