Skip to content

Commit 5daba15

Browse files
committed
Various refactorings.
1 parent 8b65677 commit 5daba15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+145
-172
lines changed

ReClass.NET/AddressParser/AstBuilder.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AstBuilder
1111
{
1212
private readonly Dictionary<char, int> operationPrecedence;
1313

14-
private readonly Stack<Operation> resultStack = new Stack<Operation>();
14+
private readonly Stack<IOperation> resultStack = new Stack<IOperation>();
1515
private readonly Stack<Token> operatorStack = new Stack<Token>();
1616

1717
public AstBuilder()
@@ -29,7 +29,7 @@ public AstBuilder()
2929
};
3030
}
3131

32-
public Operation Build(IEnumerable<Token> tokens)
32+
public IOperation Build(IEnumerable<Token> tokens)
3333
{
3434
Contract.Requires(tokens != null);
3535
Contract.Ensures(Contract.ForAll(tokens, t => t != null));
@@ -119,14 +119,14 @@ private void PopOperations(bool untillLeftBracket)
119119
}
120120
}
121121

122-
private Operation ConvertOperation(Token operationToken)
122+
private IOperation ConvertOperation(Token operationToken)
123123
{
124124
Contract.Requires(operationToken != null);
125125

126126
try
127127
{
128-
Operation argument1;
129-
Operation argument2;
128+
IOperation argument1;
129+
IOperation argument2;
130130

131131
switch ((char)operationToken.Value)
132132
{
@@ -163,8 +163,7 @@ private void VerifyResultStack()
163163
{
164164
if (resultStack.Count > 1)
165165
{
166-
var offset = resultStack.Skip(1).FirstOrDefault(o => o is OffsetOperation) as OffsetOperation;
167-
if (offset != null)
166+
if (resultStack.Skip(1).FirstOrDefault(o => o is OffsetOperation) is OffsetOperation offset)
168167
{
169168
throw new ParseException($"Unexpected offset '{offset.Value}' found.");
170169
}

ReClass.NET/AddressParser/Interpreter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace ReClassNET.AddressParser
99
{
1010
class Interpreter
1111
{
12-
public IntPtr Execute(Operation operation, RemoteProcess process)
12+
public IntPtr Execute(IOperation operation, RemoteProcess process)
1313
{
1414
Contract.Requires(operation != null);
1515
Contract.Requires(process != null);

ReClass.NET/AddressParser/Operations.cs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
namespace ReClassNET.AddressParser
77
{
8-
interface Operation
8+
internal interface IOperation
99
{
1010

1111
}
1212

13-
class OffsetOperation : Operation
13+
internal class OffsetOperation : IOperation
1414
{
1515
public OffsetOperation(IntPtr value)
1616
{
@@ -21,8 +21,7 @@ public OffsetOperation(IntPtr value)
2121

2222
public override bool Equals(object obj)
2323
{
24-
var other = obj as OffsetOperation;
25-
if (other != null)
24+
if (obj is OffsetOperation other)
2625
{
2726
return Value.Equals(other.Value);
2827
}
@@ -38,21 +37,21 @@ public override int GetHashCode()
3837
}
3938
}
4039

41-
class ReadPointerOperation : Operation
40+
internal class ReadPointerOperation : IOperation
4241
{
43-
public ReadPointerOperation(Operation argument)
42+
public ReadPointerOperation(IOperation argument)
4443
{
4544
Contract.Requires(argument != null);
4645

4746
Argument = argument;
4847
}
4948

50-
public Operation Argument { get; }
49+
public IOperation Argument { get; }
5150
}
5251

53-
class AdditionOperation : Operation
52+
internal class AdditionOperation : IOperation
5453
{
55-
public AdditionOperation(Operation argument1, Operation argument2)
54+
public AdditionOperation(IOperation argument1, IOperation argument2)
5655
{
5756
Contract.Requires(argument1 != null);
5857
Contract.Requires(argument2 != null);
@@ -61,13 +60,13 @@ public AdditionOperation(Operation argument1, Operation argument2)
6160
Argument2 = argument2;
6261
}
6362

64-
public Operation Argument1 { get; }
65-
public Operation Argument2 { get; }
63+
public IOperation Argument1 { get; }
64+
public IOperation Argument2 { get; }
6665
}
6766

68-
class SubtractionOperation : Operation
67+
internal class SubtractionOperation : IOperation
6968
{
70-
public SubtractionOperation(Operation argument1, Operation argument2)
69+
public SubtractionOperation(IOperation argument1, IOperation argument2)
7170
{
7271
Contract.Requires(argument1 != null);
7372
Contract.Requires(argument2 != null);
@@ -76,13 +75,13 @@ public SubtractionOperation(Operation argument1, Operation argument2)
7675
Argument2 = argument2;
7776
}
7877

79-
public Operation Argument1 { get; }
80-
public Operation Argument2 { get; }
78+
public IOperation Argument1 { get; }
79+
public IOperation Argument2 { get; }
8180
}
8281

83-
class DivisionOperation : Operation
82+
internal class DivisionOperation : IOperation
8483
{
85-
public DivisionOperation(Operation dividend, Operation divisor)
84+
public DivisionOperation(IOperation dividend, IOperation divisor)
8685
{
8786
Contract.Requires(dividend != null);
8887
Contract.Requires(divisor != null);
@@ -91,13 +90,13 @@ public DivisionOperation(Operation dividend, Operation divisor)
9190
Divisor = divisor;
9291
}
9392

94-
public Operation Dividend { get; }
95-
public Operation Divisor { get; }
93+
public IOperation Dividend { get; }
94+
public IOperation Divisor { get; }
9695
}
9796

98-
class MultiplicationOperation : Operation
97+
internal class MultiplicationOperation : IOperation
9998
{
100-
public MultiplicationOperation(Operation argument1, Operation argument2)
99+
public MultiplicationOperation(IOperation argument1, IOperation argument2)
101100
{
102101
Contract.Requires(argument1 != null);
103102
Contract.Requires(argument2 != null);
@@ -106,11 +105,11 @@ public MultiplicationOperation(Operation argument1, Operation argument2)
106105
Argument2 = argument2;
107106
}
108107

109-
public Operation Argument1 { get; }
110-
public Operation Argument2 { get; }
108+
public IOperation Argument1 { get; }
109+
public IOperation Argument2 { get; }
111110
}
112111

113-
class ModuleOffsetOperation : Operation
112+
internal class ModuleOffsetOperation : IOperation
114113
{
115114
public ModuleOffsetOperation(string name)
116115
{
@@ -123,8 +122,7 @@ public ModuleOffsetOperation(string name)
123122

124123
public override bool Equals(object obj)
125124
{
126-
var other = obj as ModuleOffsetOperation;
127-
if (other != null)
125+
if (obj is ModuleOffsetOperation other)
128126
{
129127
return Name.Equals(other.Name);
130128
}

ReClass.NET/CodeGenerator/CSharpCodeGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ private IEnumerable<MemberDefinition> YieldMemberDefinitions(IEnumerable<BaseNod
8787

8888
foreach (var member in members.WhereNot(n => n is BaseHexNode))
8989
{
90-
var bitFieldNode = member as BitFieldNode;
91-
if (bitFieldNode != null)
90+
if (member is BitFieldNode bitFieldNode)
9291
{
9392
string type;
9493
switch (bitFieldNode.Bits)

ReClass.NET/CodeGenerator/CppCodeGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
5858
csb.Append($"class {c.Name}");
5959

6060
bool skipFirstMember = false;
61-
var inheritedFromNode = c.Nodes.FirstOrDefault() as ClassInstanceNode;
62-
if (inheritedFromNode != null)
61+
if (c.Nodes.FirstOrDefault() is ClassInstanceNode inheritedFromNode)
6362
{
6463
skipFirstMember = true;
6564

ReClass.NET/CodeGenerator/CustomCodeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace ReClassNET.CodeGenerator
99
{
10-
[ContractClass(typeof(ICustomCodeGeneratorContract))]
10+
[ContractClass(typeof(CustomCodeGeneratorContract))]
1111
public interface ICustomCodeGenerator
1212
{
1313
bool CanGenerateCode(BaseNode node, Language language);
@@ -16,7 +16,7 @@ public interface ICustomCodeGenerator
1616
}
1717

1818
[ContractClassFor(typeof(ICustomCodeGenerator))]
19-
internal abstract class ICustomCodeGeneratorContract : ICustomCodeGenerator
19+
internal abstract class CustomCodeGeneratorContract : ICustomCodeGenerator
2020
{
2121
public bool CanGenerateCode(BaseNode node, Language language)
2222
{

ReClass.NET/DataExchange/Scanner/CheatEngineFile.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,7 @@ public IEnumerable<MemoryRecord> Load(string filePath, ILogger logger)
8080
{
8181
var isUnicode = (entry.Element(XmlUnicodeElement)?.Value ?? string.Empty) == "1";
8282

83-
if (isUnicode)
84-
{
85-
record.Encoding = Encoding.Unicode;
86-
}
87-
else
88-
{
89-
record.Encoding = Encoding.UTF8;
90-
}
83+
record.Encoding = isUnicode ? Encoding.Unicode : Encoding.UTF8;
9184
}
9285
}
9386

ReClass.NET/DataExchange/Scanner/ReClassScanFile.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public IEnumerable<MemoryRecord> Load(string filePath, ILogger logger)
100100
switch (element.Attribute(XmlEncodingAttribute)?.Value ?? string.Empty)
101101
{
102102
default:
103-
case "UTF8":
104103
record.Encoding = Encoding.UTF8;
105104
break;
106105
case "UTF16":

ReClass.NET/Debugger/IBreakpoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace ReClassNET.Debugger
66
{
77
public delegate void BreakpointHandler(IBreakpoint breakpoint, ref DebugEvent evt);
88

9+
[ContractClass(typeof(BreakpointContract))]
910
public interface IBreakpoint
1011
{
1112
IntPtr Address { get; }
@@ -17,7 +18,7 @@ public interface IBreakpoint
1718
}
1819

1920
[ContractClassFor(typeof(IBreakpoint))]
20-
internal abstract class IBreakpointContract : IBreakpoint
21+
internal abstract class BreakpointContract : IBreakpoint
2122
{
2223
public IntPtr Address => throw new NotImplementedException();
2324

ReClass.NET/Debugger/RemoteDebugger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private HardwareBreakpointRegister GetUsableDebugRegister()
212212

213213
internal class BreakpointSplit
214214
{
215-
public IntPtr Address;
216-
public int Size;
215+
public IntPtr Address { get; set; }
216+
public int Size { get; set; }
217217
}
218218
}

0 commit comments

Comments
 (0)