Skip to content

Commit c22e284

Browse files
committed
Added Contract suggestions.
1 parent 83575cc commit c22e284

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

Forms/InputBytesForm.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ReClassNET.Forms
66
{
77
public partial class InputBytesForm : IconForm
88
{
9-
private int currentSize;
9+
private readonly int currentSize;
1010

1111
public int Bytes => (int)bytesNumericUpDown.Value;
1212

Memory/Memory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public byte ReadByte(int offset)
8080
public byte[] ReadBytes(int offset, int length)
8181
{
8282
Contract.Requires(offset >= 0);
83+
Contract.Requires(length >= 0);
8384

8485
var bytes = new byte[length];
8586

@@ -166,20 +167,23 @@ private string ReadString(Encoding encoding, int offset, int length)
166167

167168
public string ReadUTF8String(IntPtr offset, int length)
168169
{
170+
Contract.Requires(length >= 0);
169171
Contract.Ensures(Contract.Result<string>() != null);
170172

171173
return ReadString(Encoding.UTF8, offset.ToInt32(), length);
172174
}
173175

174176
public string ReadUTF16String(IntPtr offset, int length)
175177
{
178+
Contract.Requires(length >= 0);
176179
Contract.Ensures(Contract.Result<string>() != null);
177180

178181
return ReadString(Encoding.Unicode, offset.ToInt32(), length);
179182
}
180183

181184
public string ReadUTF32String(IntPtr offset, int length)
182185
{
186+
Contract.Requires(length >= 0);
183187
Contract.Ensures(Contract.Result<string>() != null);
184188

185189
return ReadString(Encoding.UTF32, offset.ToInt32(), length);

Nodes/BaseContainerNode.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public int FindNodeIndex(BaseNode node)
3636

3737
public virtual BaseNode ReplaceChildNode(BaseNode child, Type nodeType)
3838
{
39+
Contract.Requires(nodeType != null);
40+
3941
return ReplaceChildNode(FindNodeIndex(child), nodeType);
4042
}
4143

UI/ClassNodeView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private class ClassTreeNode : TreeNode, IDisposable
2929
{
3030
public ClassNode ClassNode { get; }
3131

32-
private ValueWrapper<bool> autoExpand;
32+
private readonly ValueWrapper<bool> autoExpand;
3333

3434
/// <summary>Constructor of the class.</summary>
3535
/// <param name="node">The class node.</param>
@@ -107,7 +107,7 @@ private void RebuildClassHierarchy(HashSet<ClassNode> seen)
107107
}
108108

109109
private readonly TreeNode root;
110-
private ValueWrapper<bool> autoExpand;
110+
private readonly ValueWrapper<bool> autoExpand;
111111

112112
private ClassNode selectedClass;
113113

Util/Extensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public static bool IsNearlyEqual(this float val, float other, float epsilon)
235235
{
236236
return true;
237237
}
238-
else if (val == 0 || other == 0 || diff < float.Epsilon)
238+
else if (val == 0.0f || other == 0.0f || diff < float.Epsilon)
239239
{
240240
return diff < epsilon;
241241
}
@@ -260,7 +260,7 @@ public static bool IsNearlyEqual(this double val, double other, double epsilon)
260260
{
261261
return true;
262262
}
263-
else if (val == 0 || other == 0 || diff < double.Epsilon)
263+
else if (val == 0.0 || other == 0.0 || diff < double.Epsilon)
264264
{
265265
return diff < epsilon;
266266
}

Util/Util.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.Contracts;
34

45
namespace ReClassNET.Util
56
{
67
public static class Utils
78
{
89
public static T Min<T, U>(T item1, T item2, Func<T, U> keySelector) where U : IComparable
910
{
11+
Contract.Requires(keySelector != null);
12+
1013
return Min(item1, item2, keySelector, Comparer<U>.Default);
1114
}
1215

1316
public static T Min<T, U>(T item1, T item2, Func<T, U> keySelector, IComparer<U> comparer)
1417
{
18+
Contract.Requires(keySelector != null);
19+
Contract.Requires(comparer != null);
20+
1521
if (comparer.Compare(keySelector(item1), keySelector(item2)) < 0)
1622
{
1723
return item1;
@@ -21,11 +27,16 @@ public static T Min<T, U>(T item1, T item2, Func<T, U> keySelector, IComparer<U>
2127

2228
public static T Max<T, U>(T item1, T item2, Func<T, U> keySelector) where U : IComparable
2329
{
30+
Contract.Requires(keySelector != null);
31+
2432
return Max(item1, item2, keySelector, Comparer<U>.Default);
2533
}
2634

2735
public static T Max<T, U>(T item1, T item2, Func<T, U> keySelector, IComparer<U> comparer)
2836
{
37+
Contract.Requires(keySelector != null);
38+
Contract.Requires(comparer != null);
39+
2940
if (comparer.Compare(keySelector(item1), keySelector(item2)) > 0)
3041
{
3142
return item1;

0 commit comments

Comments
 (0)