Skip to content

Commit 056db31

Browse files
committed
Enable BHI1001 and fix noncompliance
"Do not use anonymous delegates"
1 parent 395aa07 commit 056db31

File tree

15 files changed

+61
-120
lines changed

15 files changed

+61
-120
lines changed

Common.ruleset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<RuleSet Name="BizHawk Rules" Description="Applies to all projects in the solution -- or, it will eventually." ToolsVersion="14.0">
33
<Rules AnalyzerId="BizHawk.Analyzer" RuleNamespace="BizHawk.Analyzer">
44
<!-- Do not use anonymous delegates -->
5-
<Rule Id="BHI1001" Action="Hidden" />
5+
<Rule Id="BHI1001" Action="Error" />
66

77
<!-- Do not use anonymous types (classes) -->
88
<Rule Id="BHI1002" Action="Hidden" />

src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ protected virtual void LoadFields(ZipStateLoader bl, bool preload)
156156

157157
protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
158158
{
159-
bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr)
159+
bl.GetLump(BinaryStateLump.Movieheader, abort: true, tr =>
160160
{
161161
string line;
162162
while ((line = tr.ReadLine()) != null)
@@ -176,7 +176,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
176176
}
177177
});
178178

179-
bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)
179+
bl.GetLump(BinaryStateLump.Input, abort: true, tr =>
180180
{
181181
IsCountingRerecords = false;
182182
ExtractInputLog(tr, out _);
@@ -188,7 +188,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
188188
return;
189189
}
190190

191-
bl.GetLump(BinaryStateLump.Comments, false, delegate(TextReader tr)
191+
bl.GetLump(BinaryStateLump.Comments, abort: false, tr =>
192192
{
193193
string line;
194194
while ((line = tr.ReadLine()) != null)
@@ -200,7 +200,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
200200
}
201201
});
202202

203-
bl.GetLump(BinaryStateLump.Subtitles, false, delegate(TextReader tr)
203+
bl.GetLump(BinaryStateLump.Subtitles, abort: false, tr =>
204204
{
205205
string line;
206206
while ((line = tr.ReadLine()) != null)
@@ -214,7 +214,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
214214
Subtitles.Sort();
215215
});
216216

217-
bl.GetLump(BinaryStateLump.SyncSettings, false, delegate(TextReader tr)
217+
bl.GetLump(BinaryStateLump.SyncSettings, abort: false, tr =>
218218
{
219219
string line;
220220
while ((line = tr.ReadLine()) != null)
@@ -229,16 +229,10 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
229229
if (StartsFromSavestate)
230230
{
231231
bl.GetCoreState(
232-
delegate(BinaryReader br, long length)
233-
{
234-
BinarySavestate = br.ReadBytes((int)length);
235-
},
236-
delegate(TextReader tr)
237-
{
238-
TextSavestate = tr.ReadToEnd();
239-
});
232+
(br, length) => BinarySavestate = br.ReadBytes((int) length),
233+
tr => TextSavestate = tr.ReadToEnd());
240234
bl.GetLump(BinaryStateLump.Framebuffer, false,
241-
delegate(BinaryReader br, long length)
235+
(br, length) =>
242236
{
243237
SavestateFramebuffer = new int[length / sizeof(int)];
244238
for (int i = 0; i < SavestateFramebuffer.Length; i++)
@@ -250,10 +244,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
250244
else if (StartsFromSaveRam)
251245
{
252246
bl.GetLump(BinaryStateLump.MovieSaveRam, false,
253-
delegate(BinaryReader br, long length)
254-
{
255-
SaveRam = br.ReadBytes((int)length);
256-
});
247+
(br, length) => SaveRam = br.ReadBytes((int) length));
257248
}
258249
}
259250
}

src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void Save(ZipStateSaver bs)
123123
var nusertext = new IndexedStateLump(BinaryStateLump.BranchUserText);
124124
foreach (var b in this)
125125
{
126-
bs.PutLump(nheader, delegate(TextWriter tw)
126+
bs.PutLump(nheader, tw =>
127127
{
128128
// if this header needs more stuff in it, handle it sensibly
129129
tw.WriteLine(JsonConvert.SerializeObject(new
@@ -134,12 +134,9 @@ public void Save(ZipStateSaver bs)
134134
}));
135135
});
136136

137-
bs.PutLump(ncore, delegate(Stream s)
138-
{
139-
s.Write(b.CoreData, 0, b.CoreData.Length);
140-
});
137+
bs.PutLump(ncore, (Stream s) => s.Write(b.CoreData, 0, b.CoreData.Length));
141138

142-
bs.PutLump(ninput, delegate(TextWriter tw)
139+
bs.PutLump(ninput, tw =>
143140
{
144141
int todo = b.InputLog.Count;
145142
for (int i = 0; i < todo; i++)
@@ -148,27 +145,21 @@ public void Save(ZipStateSaver bs)
148145
}
149146
});
150147

151-
bs.PutLump(nframebuffer, delegate(Stream s)
148+
bs.PutLump(nframebuffer, s =>
152149
{
153150
var vp = new BitmapBufferVideoProvider(b.OSDFrameBuffer);
154151
_quickBmpFile.Save(vp, s, b.OSDFrameBuffer.Width, b.OSDFrameBuffer.Height);
155152
});
156153

157-
bs.PutLump(ncoreframebuffer, delegate(Stream s)
154+
bs.PutLump(ncoreframebuffer, s =>
158155
{
159156
var vp = new BitmapBufferVideoProvider(b.CoreFrameBuffer);
160157
_quickBmpFile.Save(vp, s, b.CoreFrameBuffer.Width, b.CoreFrameBuffer.Height);
161158
});
162159

163-
bs.PutLump(nmarkers, delegate(TextWriter tw)
164-
{
165-
tw.WriteLine(b.Markers.ToString());
166-
});
160+
bs.PutLump(nmarkers, tw => tw.WriteLine(b.Markers.ToString()));
167161

168-
bs.PutLump(nusertext, delegate(TextWriter tw)
169-
{
170-
tw.WriteLine(b.UserText);
171-
});
162+
bs.PutLump(nusertext, tw => tw.WriteLine(b.UserText));
172163

173164
nheader.Increment();
174165
ncore.Increment();
@@ -196,7 +187,7 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
196187
{
197188
var b = new TasBranch();
198189

199-
if (!bl.GetLump(nheader, false, delegate(TextReader tr)
190+
if (!bl.GetLump(nheader, abort: false, tr =>
200191
{
201192
var header = (dynamic)JsonConvert.DeserializeObject(tr.ReadLine());
202193
b.Frame = (int)header.Frame;
@@ -226,13 +217,13 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
226217
return;
227218
}
228219

229-
bl.GetLump(ncore, true, delegate(Stream s, long length)
220+
bl.GetLump(ncore, abort: true, (Stream s, long length) =>
230221
{
231222
b.CoreData = new byte[length];
232223
s.Read(b.CoreData, 0, b.CoreData.Length);
233224
});
234225

235-
bl.GetLump(ninput, true, delegate(TextReader tr)
226+
bl.GetLump(ninput, abort: true, tr =>
236227
{
237228
b.InputLog = StringLogUtil.MakeStringLog();
238229
string line;
@@ -242,20 +233,20 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
242233
}
243234
});
244235

245-
bl.GetLump(nframebuffer, true, delegate(Stream s, long length)
236+
bl.GetLump(nframebuffer, abort: true, (s, _) =>
246237
{
247238
_quickBmpFile.LoadAuto(s, out var vp);
248239
b.OSDFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.GetVideoBuffer());
249240
});
250241

251-
bl.GetLump(ncoreframebuffer, false, delegate(Stream s, long length)
242+
bl.GetLump(ncoreframebuffer, abort: false, (s, _) =>
252243
{
253244
_quickBmpFile.LoadAuto(s, out var vp);
254245
b.CoreFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.GetVideoBuffer());
255246
});
256247

257248
b.Markers = new TasMovieMarkerList(movie);
258-
bl.GetLump(nmarkers, false, delegate(TextReader tr)
249+
bl.GetLump(nmarkers, abort: false, tr =>
259250
{
260251
string line;
261252
while ((line = tr.ReadLine()) != null)
@@ -267,7 +258,7 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
267258
}
268259
});
269260

270-
bl.GetLump(nusertext, false, delegate(TextReader tr)
261+
bl.GetLump(nusertext, abort: false, tr =>
271262
{
272263
string line;
273264
if ((line = tr.ReadLine()) != null)

src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ protected override void LoadFields(ZipStateLoader bl, bool preload)
8181

8282
private void LoadTasprojExtras(ZipStateLoader bl)
8383
{
84-
bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
85-
{
86-
LagLog.Load(tr);
87-
});
84+
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => LagLog.Load(tr));
8885

89-
bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
86+
bl.GetLump(BinaryStateLump.Markers, abort: false, tr =>
9087
{
9188
string line;
9289
while ((line = tr.ReadLine()) != null)
@@ -101,7 +98,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
10198
if (GetClientSettingsOnLoad != null)
10299
{
103100
string clientSettings = "";
104-
bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr)
101+
bl.GetLump(BinaryStateLump.ClientSettings, abort: false, tr =>
105102
{
106103
string line;
107104
while ((line = tr.ReadLine()) != null)
@@ -119,7 +116,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
119116
}
120117
}
121118

122-
bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr)
119+
bl.GetLump(BinaryStateLump.VerificationLog, abort: false, tr =>
123120
{
124121
VerificationLog.Clear();
125122
while (true)
@@ -139,7 +136,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
139136

140137
Branches.Load(bl, this);
141138

142-
bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
139+
bl.GetLump(BinaryStateLump.Session, abort: false, tr =>
143140
{
144141
var json = tr.ReadToEnd();
145142
try
@@ -153,7 +150,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
153150
});
154151

155152
ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings();
156-
bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
153+
bl.GetLump(BinaryStateLump.StateHistorySettings, abort: false, tr =>
157154
{
158155
var json = tr.ReadToEnd();
159156
try
@@ -166,7 +163,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
166163
}
167164
});
168165

169-
bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
166+
bl.GetLump(BinaryStateLump.StateHistory, abort: false, (br, _) =>
170167
{
171168
try
172169
{

src/BizHawk.Client.Common/savestates/SavestateFile.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void Create(string filename, SaveStateConfig config)
9797
if (_movieSession.Movie.IsActive())
9898
{
9999
bs.PutLump(BinaryStateLump.Input,
100-
delegate(TextWriter tw)
100+
tw =>
101101
{
102102
// this never should have been a core's responsibility
103103
tw.WriteLine("Frame {0}", _emulator.Frame);
@@ -108,7 +108,7 @@ public void Create(string filename, SaveStateConfig config)
108108
if (_userBag.Any())
109109
{
110110
bs.PutLump(BinaryStateLump.UserData,
111-
delegate(TextWriter tw)
111+
tw =>
112112
{
113113
var data = ConfigService.SaveWithType(_userBag);
114114
tw.WriteLine(data);
@@ -117,11 +117,7 @@ public void Create(string filename, SaveStateConfig config)
117117

118118
if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
119119
{
120-
bs.PutLump(BinaryStateLump.LagLog,
121-
delegate(TextWriter tw)
122-
{
123-
((ITasMovie)_movieSession.Movie).LagLog.Save(tw);
124-
});
120+
bs.PutLump(BinaryStateLump.LagLog, tw => ((ITasMovie) _movieSession.Movie).LagLog.Save(tw));
125121
}
126122
}
127123

@@ -177,7 +173,7 @@ public bool Load(string path, IDialogParent dialogParent)
177173
}
178174

179175
string userData = "";
180-
bl.GetLump(BinaryStateLump.UserData, false, delegate(TextReader tr)
176+
bl.GetLump(BinaryStateLump.UserData, abort: false, tr =>
181177
{
182178
string line;
183179
while ((line = tr.ReadLine()) != null)
@@ -198,10 +194,7 @@ public bool Load(string path, IDialogParent dialogParent)
198194

199195
if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
200196
{
201-
bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
202-
{
203-
((ITasMovie)_movieSession.Movie).LagLog.Load(tr);
204-
});
197+
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => ((ITasMovie) _movieSession.Movie).LagLog.Load(tr));
205198
}
206199

207200
return true;

src/BizHawk.Client.Common/savestates/ZipStateLoader.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,13 @@ public bool GetLump(BinaryStateLump lump, bool abort, Action<Stream, long> callb
123123
}
124124

125125
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
126-
{
127-
return GetLump(lump, abort, delegate(Stream s, long unused)
128-
{
129-
var br = new BinaryReader(s);
130-
callback(br);
131-
});
132-
}
126+
=> GetLump(lump, abort, (s, _) => callback(new(s)));
133127

134128
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader, long> callback)
135-
{
136-
return GetLump(lump, abort, delegate(Stream s, long length)
137-
{
138-
var br = new BinaryReader(s);
139-
callback(br, length);
140-
});
141-
}
129+
=> GetLump(lump, abort, (s, length) => callback(new(s), length));
142130

143131
public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
144-
{
145-
return GetLump(lump, abort, delegate(Stream s, long unused)
146-
{
147-
var tr = new StreamReader(s);
148-
callback(tr);
149-
});
150-
}
132+
=> GetLump(lump, abort, (s, _) => callback(new StreamReader(s)));
151133

152134
/// <exception cref="Exception">couldn't find Binary or Text savestate</exception>
153135
public void GetCoreState(Action<BinaryReader, long> callbackBinary, Action<TextReader> callbackText)

src/BizHawk.Client.Common/savestates/ZipStateSaver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void PutLump(BinaryStateLump lump, Action<Stream> callback)
4242

4343
public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
4444
{
45-
PutLump(lump, delegate(Stream s)
45+
PutLump(lump, s =>
4646
{
4747
var bw = new BinaryWriter(s);
4848
callback(bw);
@@ -52,7 +52,7 @@ public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
5252

5353
public void PutLump(BinaryStateLump lump, Action<TextWriter> callback)
5454
{
55-
PutLump(lump, delegate(Stream s)
55+
PutLump(lump, s =>
5656
{
5757
TextWriter tw = new StreamWriter(s);
5858
callback(tw);

src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.MemoryDomains.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ private void InitMemoryDomains()
8787
var name = $"{ deviceName } : { read } : 0x{ firstOffset:X}-0x{ lastOffset:X}";
8888

8989
domains.Add(new MemoryDomainDelegate(name, lastOffset - firstOffset + 1, endian,
90-
delegate (long addr)
91-
{
92-
return _peek(addr, firstOffset, size);
93-
},
90+
addr => _peek(addr, firstOffset, size),
9491
read == "rom"
9592
? null
9693
: (long addr, byte val) => _poke(addr, val, firstOffset, size),
@@ -99,10 +96,7 @@ private void InitMemoryDomains()
9996
}
10097

10198
domains.Add(new MemoryDomainDelegate(deviceName + " : System Bus", size, endian,
102-
delegate (long addr)
103-
{
104-
return _peek(addr, 0, size);
105-
},
99+
addr => _peek(addr, 0, size),
106100
null, dataWidth));
107101

108102
_memoryDomains = new MemoryDomainList(domains);

0 commit comments

Comments
 (0)