Code cleanup
Rob Mensching committed
Feb 5, 2020 at 14:36 UTC
df8f367c7bc515be7f5652338f1e64e6a9e6acd8
5 files changed
+117
-606
src/WixToolset.Data/WindowsInstaller/Rows/FileRow.cs
+50
-475
@@ -2,41 +2,13 @@
2
3
namespace WixToolset.Data.WindowsInstaller.Rows
4
{
5
- using System;
5
using System.Diagnostics;
7
- using System.Globalization;
6
7
/// <summary>
8
/// Specialization of a row for the file table.
9
/// </summary>
12
- public sealed class FileRow : Row //, IComparable
10
+ public sealed class FileRow : Row
11
{
14
- //private string assemblyApplication;
15
- //private string assemblyManifest;
16
- //private FileAssemblyType assemblyType;
17
- //private string directory;
18
- //private int diskId;
19
- //private bool fromModule;
20
- //private bool isGeneratedShortFileName;
21
- //private int patchGroup;
22
- //private string processorArchitecture;
23
- //private string source;
24
- //private Row hashRow;
25
- //private List<Row> assemblyNameRows;
26
- //private string[] previousSource;
27
- //private string symbols;
28
- //private string[] previousSymbols;
29
- //private PatchAttributeType patchAttributes;
30
- //private string retainOffsets;
31
- //private string retainLengths;
32
- //private string ignoreOffsets;
33
- //private string ignoreLengths;
34
- //private string[] previousRetainOffsets;
35
- //private string[] previousRetainLengths;
36
- //private string[] previousIgnoreOffsets;
37
- //private string[] previousIgnoreLengths;
38
- //private string patch;
39
-
12
/// <summary>
13
/// Creates a File row that belongs to a table.
14
/// </summary>
@@ -45,13 +17,6 @@ namespace WixToolset.Data.WindowsInstaller.Rows
17
public FileRow(SourceLineNumber sourceLineNumbers, Table table)
18
: base(sourceLineNumbers, table)
19
{
48
- //this.assemblyType = FileAssemblyType.NotAnAssembly;
49
- //this.previousSource = new string[1];
50
- //this.previousSymbols = new string[1];
51
- //this.previousRetainOffsets = new string[1];
52
- //this.previousRetainLengths = new string[1];
53
- //this.previousIgnoreOffsets = new string[1];
54
- //this.previousIgnoreLengths = new string[1];
20
}
21
22
/// <summary>
@@ -62,13 +27,6 @@ namespace WixToolset.Data.WindowsInstaller.Rows
27
public FileRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDefinition)
28
: base(sourceLineNumbers, tableDefinition)
29
{
65
- //this.assemblyType = FileAssemblyType.NotAnAssembly;
66
- //this.previousSource = new string[1];
67
- //this.previousSymbols = new string[1];
68
- //this.previousRetainOffsets = new string[1];
69
- //this.previousRetainLengths = new string[1];
70
- //this.previousIgnoreOffsets = new string[1];
71
- //this.previousIgnoreLengths = new string[1];
30
}
31
32
/// <summary>
@@ -77,8 +35,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
35
/// <value>Primary key of the file row.</value>
36
public string File
37
{
80
- get { return (string)this.Fields[0].Data; }
81
- set { this.Fields[0].Data = value; }
38
+ get => this.FieldAsString(0);
39
+ set => this.Fields[0].Data = value;
40
}
41
42
/// <summary>
@@ -87,8 +45,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
45
/// <value>Component this file row belongs to.</value>
46
public string Component
47
{
90
- get { return (string)this.Fields[1].Data; }
91
- set { this.Fields[1].Data = value; }
48
+ get => this.FieldAsString(1);
49
+ set => this.Fields[1].Data = value;
50
}
51
52
/// <summary>
@@ -97,8 +55,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
55
/// <value>Name of the file.</value>
56
public string FileName
57
{
100
- get { return (string)this.Fields[2].Data; }
101
- set { this.Fields[2].Data = value; }
58
+ get => this.FieldAsString(2);
59
+ set => this.Fields[2].Data = value;
60
}
61
62
/// <summary>
@@ -110,18 +68,12 @@ namespace WixToolset.Data.WindowsInstaller.Rows
68
{
69
get
70
{
113
- string fileName = this.FileName;
114
- int index = fileName.IndexOf('|');
71
+ var fileName = this.FileName;
72
+ var index = fileName.IndexOf('|');
73
74
// If it doesn't contain a pipe, just return the whole string
117
- if (-1 == index)
118
- {
119
- return fileName;
120
- }
121
- else // otherwise, extract the part of the string after the pipe
122
- {
123
- return fileName.Substring(index + 1);
124
- }
75
+ // otherwise, extract the part of the string after the pipe.
76
+ return (-1 == index) ? fileName : fileName.Substring(index + 1);
77
}
78
}
79
@@ -131,8 +83,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
83
/// <value>Size of the file.</value>
84
public int FileSize
85
{
134
- get { return (int)this.Fields[3].Data; }
135
- set { this.Fields[3].Data = value; }
86
+ get => this.FieldAsInteger(3);
87
+ set => this.Fields[3].Data = value;
88
}
89
90
/// <summary>
@@ -141,8 +93,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
93
/// <value>Version of the file.</value>
94
public string Version
95
{
144
- get { return (string)this.Fields[4].Data; }
145
- set { this.Fields[4].Data = value; }
96
+ get => this.FieldAsString(4);
97
+ set => this.Fields[4].Data = value;
98
}
99
100
/// <summary>
@@ -151,8 +103,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
103
/// <value>LCID of the file.</value>
104
public string Language
105
{
154
- get { return (string)this.Fields[5].Data; }
155
- set { this.Fields[5].Data = value; }
106
+ get => this.FieldAsString(5);
107
+ set => this.Fields[5].Data = value;
108
}
109
110
/// <summary>
@@ -161,8 +113,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
113
/// <value>Attributes on a file.</value>
114
public int Attributes
115
{
164
- get { return Convert.ToInt32(this.Fields[6].Data, CultureInfo.InvariantCulture); }
165
- set { this.Fields[6].Data = value; }
116
+ get => this.FieldAsInteger(6);
117
+ set => this.Fields[6].Data = value;
118
}
119
120
/// <summary>
@@ -173,8 +125,8 @@ namespace WixToolset.Data.WindowsInstaller.Rows
125
{
126
get
127
{
176
- bool compressedFlag = (0 < (this.Attributes & WindowsInstallerConstants.MsidbFileAttributesCompressed));
177
- bool noncompressedFlag = (0 < (this.Attributes & WindowsInstallerConstants.MsidbFileAttributesNoncompressed));
128
+ var compressedFlag = (0 < (this.Attributes & WindowsInstallerConstants.MsidbFileAttributesCompressed));
129
+ var noncompressedFlag = (0 < (this.Attributes & WindowsInstallerConstants.MsidbFileAttributesNoncompressed));
130
131
if (compressedFlag && noncompressedFlag)
132
{
@@ -225,415 +177,38 @@ namespace WixToolset.Data.WindowsInstaller.Rows
177
/// <value>Sequence of the file row.</value>
178
public int Sequence
179
{
228
- get { return (int)this.Fields[7].Data; }
229
- set { this.Fields[7].Data = value; }
180
+ get => this.FieldAsInteger(7);
181
+ set => this.Fields[7].Data = value;
182
}
183
232
- /////// <summary>
233
- /////// Gets or sets the type of assembly of file row.
234
- /////// </summary>
235
- /////// <value>Assembly type for file row.</value>
236
- ////public FileAssemblyType AssemblyType
237
- ////{
238
- //// get { return this.assemblyType; }
239
- //// set { this.assemblyType = value; }
240
- ////}
241
-
242
- /////// <summary>
243
- /////// Gets or sets the identifier for the assembly application.
244
- /////// </summary>
245
- /////// <value>Identifier for the assembly application.</value>
246
- ////public string AssemblyApplication
247
- ////{
248
- //// get { return this.assemblyApplication; }
249
- //// set { this.assemblyApplication = value; }
250
- ////}
251
-
252
- /////// <summary>
253
- /////// Gets or sets the identifier for the assembly manifest.
254
- /////// </summary>
255
- /////// <value>Identifier for the assembly manifest.</value>
256
- ////public string AssemblyManifest
257
- ////{
258
- //// get { return this.assemblyManifest; }
259
- //// set { this.assemblyManifest = value; }
260
- ////}
261
-
262
- /////// <summary>
263
- /////// Gets or sets the directory of the file.
264
- /////// </summary>
265
- /////// <value>Directory of the file.</value>
266
- ////public string Directory
267
- ////{
268
- //// get { return this.directory; }
269
- //// set { this.directory = value; }
270
- ////}
271
-
272
- /////// <summary>
273
- /////// Gets or sets the disk id for this file.
274
- /////// </summary>
275
- /////// <value>Disk id for the file.</value>
276
- ////public int DiskId
277
- ////{
278
- //// get { return this.diskId; }
279
- //// set { this.diskId = value; }
280
- ////}
281
-
282
- /////// <summary>
283
- /////// Gets or sets the source location to the file.
284
- /////// </summary>
285
- /////// <value>Source location to the file.</value>
286
- ////public string Source
287
- ////{
288
- //// get { return this.source; }
289
- //// set { this.source = value; }
290
- ////}
291
-
292
- /////// <summary>
293
- /////// Gets or sets the source location to the previous file.
294
- /////// </summary>
295
- /////// <value>Source location to the previous file.</value>
296
- ////public string PreviousSource
297
- ////{
298
- //// get { return this.previousSource[0]; }
299
- //// set { this.previousSource[0] = value; }
300
- ////}
301
-
302
- /////// <summary>
303
- /////// Gets the source location to the previous files.
304
- /////// </summary>
305
- /////// <value>Source location to the previous files.</value>
306
- ////[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
307
- ////public string[] PreviousSourceArray
308
- ////{
309
- //// get { return this.previousSource; }
310
- ////}
311
-
312
- /////// <summary>
313
- /////// Gets or sets the architecture the file executes on.
314
- /////// </summary>
315
- /////// <value>Architecture the file executes on.</value>
316
- ////public string ProcessorArchitecture
317
- ////{
318
- //// get { return this.processorArchitecture; }
319
- //// set { this.processorArchitecture = value; }
320
- ////}
321
-
322
- /////// <summary>
323
- /////// Gets of sets the patch group of a patch-added file.
324
- /////// </summary>
325
- /////// <value>The patch group of a patch-added file.</value>
326
- ////public int PatchGroup
327
- ////{
328
- //// get { return this.patchGroup; }
329
- //// set { this.patchGroup = value; }
330
- ////}
331
-
332
- /////// <summary>
333
- /////// Gets or sets the patch header of the file.
334
- /////// </summary>
335
- /////// <value>Patch header of the file.</value>
336
- ////public string Patch
337
- ////{
338
- //// get { return this.patch; }
339
- //// set { this.patch = value; }
340
- ////}
341
-
342
- /////// <summary>
343
- /////// Gets or sets the locations to find the file's symbols.
344
- /////// </summary>
345
- /////// <value>Symbol paths for the file.</value>
346
- ////public string Symbols
347
- ////{
348
- //// get { return this.symbols; }
349
- //// set { this.symbols = value; }
350
- ////}
351
-
352
- /////// <summary>
353
- /////// Gets or sets the locations to find the file's previous symbols.
354
- /////// </summary>
355
- /////// <value>Symbol paths for the previous file.</value>
356
- ////public string PreviousSymbols
357
- ////{
358
- //// get { return this.previousSymbols[0]; }
359
- //// set { this.previousSymbols[0] = value; }
360
- ////}
361
-
362
- /////// <summary>
363
- /////// Gets the locations to find the files' previous symbols.
364
- /////// </summary>
365
- /////// <value>Symbol paths for the previous files.</value>
366
- ////[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
367
- ////public string[] PreviousSymbolsArray
368
- ////{
369
- //// get { return this.previousSymbols; }
370
- ////}
371
-
372
- /////// <summary>
373
- /////// Gets or sets the generated short file name attribute.
374
- /////// </summary>
375
- /////// <value>The generated short file name attribute.</value>
376
- ////public bool IsGeneratedShortFileName
377
- ////{
378
- //// get { return this.isGeneratedShortFileName; }
379
-
380
- //// set { this.isGeneratedShortFileName = value; }
381
- ////}
382
-
383
- /////// <summary>
384
- /////// Gets or sets whether this row came from a merge module.
385
- /////// </summary>
386
- /////// <value>Whether this row came from a merge module.</value>
387
- ////public bool FromModule
388
- ////{
389
- //// get { return this.fromModule; }
390
- //// set { this.fromModule = value; }
391
- ////}
392
-
393
- /////// <summary>
394
- /////// Gets or sets the MsiFileHash row created for this FileRow.
395
- /////// </summary>
396
- /////// <value>Row for MsiFileHash table.</value>
397
- ////public Row HashRow
398
- ////{
399
- //// get { return this.hashRow; }
400
- //// set { this.hashRow = value; }
401
- ////}
402
-
403
- /////// <summary>
404
- /////// Gets or sets the set of MsiAssemblyName rows created for this FileRow.
405
- /////// </summary>
406
- /////// <value>RowCollection of MsiAssemblyName table.</value>
407
- ////[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
408
- ////public List<Row> AssemblyNameRows
409
- ////{
410
- //// get { return this.assemblyNameRows; }
411
- //// set { this.assemblyNameRows = value; }
412
- ////}
413
-
414
- /////// <summary>
415
- /////// Gets or sets the patching attributes to the file.
416
- /////// </summary>
417
- /////// <value>Patching attributes of the file.</value>
418
- ////public PatchAttributeType PatchAttributes
419
- ////{
420
- //// get { return this.patchAttributes; }
421
- //// set { this.patchAttributes = value; }
422
- ////}
423
-
424
- /////// <summary>
425
- /////// Gets or sets the delta patch retain-length list for the file.
426
- /////// </summary>
427
- /////// <value>RetainLength list for the file.</value>
428
- ////public string RetainLengths
429
- ////{
430
- //// get { return this.retainLengths; }
431
- //// set { this.retainLengths = value; }
432
- ////}
433
-
434
- /////// <summary>
435
- /////// Gets or sets the delta patch ignore-offset list for the file.
436
- /////// </summary>
437
- /////// <value>IgnoreOffset list for the file.</value>
438
- ////public string IgnoreOffsets
439
- ////{
440
- //// get { return this.ignoreOffsets; }
441
- //// set { this.ignoreOffsets = value; }
442
- ////}
443
-
444
- /////// <summary>
445
- /////// Gets or sets the delta patch ignore-length list for the file.
446
- /////// </summary>
447
- /////// <value>IgnoreLength list for the file.</value>
448
- ////public string IgnoreLengths
449
- ////{
450
- //// get { return this.ignoreLengths; }
451
- //// set { this.ignoreLengths = value; }
452
- ////}
453
-
454
- /////// <summary>
455
- /////// Gets or sets the delta patch retain-offset list for the file.
456
- /////// </summary>
457
- /////// <value>RetainOffset list for the file.</value>
458
- ////public string RetainOffsets
459
- ////{
460
- //// get { return this.retainOffsets; }
461
- //// set { this.retainOffsets = value; }
462
- ////}
463
-
464
- /////// <summary>
465
- /////// Gets or sets the delta patch retain-length list for the previous file.
466
- /////// </summary>
467
- /////// <value>RetainLength list for the previous file.</value>
468
- ////public string PreviousRetainLengths
469
- ////{
470
- //// get { return this.previousRetainLengths[0]; }
471
- //// set { this.previousRetainLengths[0] = value; }
472
- ////}
473
-
474
- /////// <summary>
475
- /////// Gets the delta patch retain-length list for the previous files.
476
- /////// </summary>
477
- /////// <value>RetainLength list for the previous files.</value>
478
- ////[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
479
- ////public string[] PreviousRetainLengthsArray
480
- ////{
481
- //// get { return this.previousRetainLengths; }
482
- ////}
483
-
484
- /////// <summary>
485
- /////// Gets or sets the delta patch ignore-offset list for the previous file.
486
- /////// </summary>
487
- /////// <value>IgnoreOffset list for the previous file.</value>
488
- ////public string PreviousIgnoreOffsets
489
- ////{
490
- //// get { return this.previousIgnoreOffsets[0]; }
491
- //// set { this.previousIgnoreOffsets[0] = value; }
492
- ////}
493
-
494
- /////// <summary>
495
- /////// Gets the delta patch ignore-offset list for the previous files.
496
- /////// </summary>
497
- /////// <value>IgnoreOffset list for the previous files.</value>
498
- ////[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
499
- ////public string[] PreviousIgnoreOffsetsArray
500
- ////{
501
- //// get { return this.previousIgnoreOffsets; }
502
- ////}
503
-
504
- /////// <summary>
505
- /////// Gets or sets the delta patch ignore-length list for the previous file.
506
- /////// </summary>
507
- /////// <value>IgnoreLength list for the previous file.</value>
508
- ////public string PreviousIgnoreLengths
509
- ////{
510
- //// get { return this.previousIgnoreLengths[0]; }
511
- //// set { this.previousIgnoreLengths[0] = value; }
512
- ////}
513
-
514
- /////// <summary>
515
- /////// Gets the delta patch ignore-length list for the previous files.
516
- /////// </summary>
517
- /////// <value>IgnoreLength list for the previous files.</value>
518
- ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
519
- ////public string[] PreviousIgnoreLengthsArray
520
- ////{
521
- //// get { return this.previousIgnoreLengths; }
522
- ////}
523
-
524
- /////// <summary>
525
- /////// Gets or sets the delta patch retain-offset list for the previous file.
526
- /////// </summary>
527
- /////// <value>RetainOffset list for the previous file.</value>
528
- ////public string PreviousRetainOffsets
529
- ////{
530
- //// get { return this.previousRetainOffsets[0]; }
531
- //// set { this.previousRetainOffsets[0] = value; }
532
- ////}
533
-
534
- /////// <summary>
535
- /////// Gets the delta patch retain-offset list for the previous files.
536
- /////// </summary>
537
- /////// <value>RetainOffset list for the previous files.</value>
538
- ////[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
539
- ////public string[] PreviousRetainOffsetsArray
540
- ////{
541
- //// get { return this.previousRetainOffsets; }
542
- ////}
543
-
544
- /////// <summary>
545
- /////// Compares the current FileRow with another object of the same type.
546
- /////// </summary>
547
- /////// <param name="obj">An object to compare with this instance.</param>
548
- /////// <returns>An integer that indicates the relative order of the comparands.</returns>
549
- ////[SuppressMessage("Microsoft.Globalization", "CA1303:DoNotPassLiteralsAsLocalizedParameters", MessageId = "System.ArgumentException.#ctor(System.String)")]
550
- ////[SuppressMessage("Microsoft.Globalization", "CA1309:UseOrdinalStringComparison")]
551
- ////public int CompareTo(object obj)
552
- ////{
553
- //// if (this == obj)
554
- //// {
555
- //// return 0;
556
- //// }
557
-
558
- //// FileRow fileRow = obj as FileRow;
559
- //// if (null == fileRow)
560
- //// {
561
- //// throw new ArgumentException(WixDataStrings.EXP_OtherObjectIsNotFileRow);
562
- //// }
563
-
564
- //// int compared = this.DiskId - fileRow.DiskId;
565
- //// if (0 == compared)
566
- //// {
567
- //// compared = this.patchGroup - fileRow.patchGroup;
568
-
569
- //// if (0 == compared)
570
- //// {
571
- //// compared = String.Compare(this.File, fileRow.File, StringComparison.InvariantCulture);
572
- //// }
573
- //// }
574
-
575
- //// return compared;
576
- ////}
577
-
578
- /////// <summary>
579
- /////// Copies data from another FileRow object.
580
- /////// </summary>
581
- /////// <param name="src">An row to get data from.</param>
582
- ////public void CopyFrom(FileRow src)
583
- ////{
584
- //// for (int i = 0; i < src.Fields.Length; i++)
585
- //// {
586
- //// this[i] = src[i];
587
- //// }
588
- //// this.assemblyManifest = src.assemblyManifest;
589
- //// this.assemblyType = src.assemblyType;
590
- //// this.directory = src.directory;
591
- //// this.diskId = src.diskId;
592
- //// this.fromModule = src.fromModule;
593
- //// this.isGeneratedShortFileName = src.isGeneratedShortFileName;
594
- //// this.patchGroup = src.patchGroup;
595
- //// this.processorArchitecture = src.processorArchitecture;
596
- //// this.source = src.source;
597
- //// this.PreviousSource = src.PreviousSource;
598
- //// this.Operation = src.Operation;
599
- //// this.symbols = src.symbols;
600
- //// this.PreviousSymbols = src.PreviousSymbols;
601
- //// this.patchAttributes = src.patchAttributes;
602
- //// this.retainOffsets = src.retainOffsets;
603
- //// this.retainLengths = src.retainLengths;
604
- //// this.ignoreOffsets = src.ignoreOffsets;
605
- //// this.ignoreLengths = src.ignoreLengths;
606
- //// this.PreviousRetainOffsets = src.PreviousRetainOffsets;
607
- //// this.PreviousRetainLengths = src.PreviousRetainLengths;
608
- //// this.PreviousIgnoreOffsets = src.PreviousIgnoreOffsets;
609
- //// this.PreviousIgnoreLengths = src.PreviousIgnoreLengths;
610
- ////}
184
+ /// <summary>
185
+ /// Gets or sets the disk id for this file.
186
+ /// </summary>
187
+ /// <value>Disk id for the file.</value>
188
+ public int DiskId
189
+ {
190
+ get => this.FieldAsInteger(8);
191
+ set => this.Fields[8].Data = value;
192
+ }
193
612
- /////// <summary>
613
- /////// Appends previous data from another FileRow object.
614
- /////// </summary>
615
- /////// <param name="src">An row to get data from.</param>
616
- ////public void AppendPreviousDataFrom(FileRow src)
617
- ////{
618
- //// AppendStringToArray(ref this.previousSource, src.previousSource[0]);
619
- //// AppendStringToArray(ref this.previousSymbols, src.previousSymbols[0]);
620
- //// AppendStringToArray(ref this.previousRetainOffsets, src.previousRetainOffsets[0]);
621
- //// AppendStringToArray(ref this.previousRetainLengths, src.previousRetainLengths[0]);
622
- //// AppendStringToArray(ref this.previousIgnoreOffsets, src.previousIgnoreOffsets[0]);
623
- //// AppendStringToArray(ref this.previousIgnoreLengths, src.previousIgnoreLengths[0]);
624
- ////}
194
+ /// <summary>
195
+ /// Gets or sets the source location to the file.
196
+ /// </summary>
197
+ /// <value>Source location to the file.</value>
198
+ public string Source
199
+ {
200
+ get => this.FieldAsString(9);
201
+ set => this.Fields[9].Data = value;
202
+ }
203
626
- /////// <summary>
627
- /////// Helper method for AppendPreviousDataFrom.
628
- /////// </summary>
629
- /////// <param name="source">Destination array.</param>
630
- /////// <param name="destination">Source string.</param>
631
- ////private static void AppendStringToArray(ref string[] destination, string source)
632
- ////{
633
- //// string[] result = new string[destination.Length + 1];
634
- //// destination.CopyTo(result, 0);
635
- //// result[destination.Length] = source;
636
- //// destination = result;
637
- ////}
204
+ /// <summary>
205
+ /// Gets or sets the source location to the previous file.
206
+ /// </summary>
207
+ /// <value>Source location to the previous file.</value>
208
+ public string PreviousSource
209
+ {
210
+ get => this.Fields[9].PreviousData;
211
+ set => this.Fields[9].PreviousData = value;
212
+ }
213
}
214
}
src/WixToolset.Data/WindowsInstaller/SubStorage.cs
+5
-3
@@ -39,15 +39,16 @@ namespace WixToolset.Data.WindowsInstaller
39
/// <returns>New SubStorage object.</returns>
40
internal static SubStorage Read(XmlReader reader)
41
{
42
- if (!reader.LocalName.Equals("subStorage" == reader.LocalName))
42
+ if (reader.LocalName != "subStorage")
43
{
44
throw new XmlException();
45
}
46
47
WindowsInstallerData data = null;
48
- bool empty = reader.IsEmptyElement;
48
string name = null;
49
50
+ var empty = reader.IsEmptyElement;
51
+
52
while (reader.MoveToNextAttribute())
53
{
54
switch (reader.LocalName)
@@ -60,7 +61,7 @@ namespace WixToolset.Data.WindowsInstaller
61
62
if (!empty)
63
{
63
- bool done = false;
64
+ var done = false;
65
66
while (!done && reader.Read())
67
{
@@ -76,6 +77,7 @@ namespace WixToolset.Data.WindowsInstaller
77
throw new XmlException();
78
}
79
break;
80
+
81
case XmlNodeType.EndElement:
82
done = true;
83
break;
src/WixToolset.Data/WindowsInstaller/TableDefinitionCollection.cs
+14
-47
@@ -36,18 +36,12 @@ namespace WixToolset.Data.WindowsInstaller
36
/// Gets the number of items in the collection.
37
/// </summary>
38
/// <value>Number of items in collection.</value>
39
- public int Count
40
- {
41
- get { return this.collection.Count; }
42
- }
39
+ public int Count => this.collection.Count;
40
41
/// <summary>
42
/// Table definition collections are never read-only.
43
/// </summary>
47
- public bool IsReadOnly
48
- {
49
- get { return false; }
50
- }
44
+ public bool IsReadOnly => false;
45
46
/// <summary>
47
/// Gets a table definition by name.
@@ -72,10 +66,7 @@ namespace WixToolset.Data.WindowsInstaller
66
/// <param name="tableName">Name of table to locate.</param>
67
/// <param name="table">Table definition if found.</param>
68
/// <returns>True if table definition was found otherwise false.</returns>
75
- public bool TryGet(string tableName, out TableDefinition table)
76
- {
77
- return this.collection.TryGetValue(tableName, out table);
78
- }
69
+ public bool TryGet(string tableName, out TableDefinition table) => this.collection.TryGetValue(tableName, out table);
70
71
/// <summary>
72
/// Load a table definition collection from an XmlReader.
@@ -95,76 +86,52 @@ namespace WixToolset.Data.WindowsInstaller
86
/// </summary>
87
/// <param name="tableDefinition">Table definition to add to the collection.</param>
88
/// <value>Indexes by table definition name.</value>
98
- public void Add(TableDefinition tableDefinition)
99
- {
100
- this.collection.Add(tableDefinition.Name, tableDefinition);
101
- }
89
+ public void Add(TableDefinition tableDefinition) => this.collection.Add(tableDefinition.Name, tableDefinition);
90
91
/// <summary>
92
/// Removes all table definitions from the collection.
93
/// </summary>
106
- public void Clear()
107
- {
108
- this.collection.Clear();
109
- }
94
+ public void Clear() => this.collection.Clear();
95
96
/// <summary>
97
/// Checks if the collection contains a table name.
98
/// </summary>
99
/// <param name="tableName">The table to check in the collection.</param>
100
/// <returns>True if collection contains the table.</returns>
116
- public bool Contains(string tableName)
117
- {
118
- return this.collection.ContainsKey(tableName);
119
- }
101
+ public bool Contains(string tableName) => this.collection.ContainsKey(tableName);
102
103
/// <summary>
104
/// Checks if the collection contains a table.
105
/// </summary>
106
/// <param name="table">The table to check in the collection.</param>
107
/// <returns>True if collection contains the table.</returns>
126
- public bool Contains(TableDefinition table)
127
- {
128
- return this.collection.ContainsKey(table.Name);
129
- }
108
+ public bool Contains(TableDefinition table) => this.collection.ContainsKey(table.Name);
109
110
/// <summary>
111
/// Copies table definitions to an arry.
112
/// </summary>
113
/// <param name="array">Array to copy the table definitions to.</param>
114
/// <param name="index">Index in the array to start copying at.</param>
136
- public void CopyTo(TableDefinition[] array, int index)
137
- {
138
- this.collection.Values.CopyTo(array, index);
139
- }
115
+ public void CopyTo(TableDefinition[] array, int index) => this.collection.Values.CopyTo(array, index);
116
117
/// <summary>
118
/// Removes a table definition from the collection.
119
/// </summary>
120
/// <param name="table">Table to remove from the collection.</param>
121
/// <returns>True if the table definition existed in the collection and was removed.</returns>
146
- public bool Remove(TableDefinition table)
147
- {
148
- return this.collection.Remove(table.Name);
149
- }
122
+ public bool Remove(TableDefinition table) => this.collection.Remove(table.Name);
123
124
/// <summary>
125
/// Gets enumerator for the collection.
126
/// </summary>
127
/// <returns>Enumerator for the collection.</returns>
155
- public IEnumerator<TableDefinition> GetEnumerator()
156
- {
157
- return this.collection.Values.GetEnumerator();
158
- }
128
+ public IEnumerator<TableDefinition> GetEnumerator() => this.collection.Values.GetEnumerator();
129
130
/// <summary>
131
/// Gets the untyped enumerator for the collection.
132
/// </summary>
133
/// <returns>Untyped enumerator for the collection.</returns>
164
- IEnumerator IEnumerable.GetEnumerator()
165
- {
166
- return this.collection.Values.GetEnumerator();
167
- }
134
+ IEnumerator IEnumerable.GetEnumerator() => this.collection.Values.GetEnumerator();
135
136
/// <summary>
137
/// Loads a collection of table definitions from a XmlReader in memory.
@@ -178,8 +145,8 @@ namespace WixToolset.Data.WindowsInstaller
145
throw new XmlException();
146
}
147
181
- bool empty = reader.IsEmptyElement;
182
- TableDefinitionCollection tableDefinitionCollection = new TableDefinitionCollection();
148
+ var empty = reader.IsEmptyElement;
149
+ var tableDefinitionCollection = new TableDefinitionCollection();
150
151
while (reader.MoveToNextAttribute())
152
{
@@ -188,7 +155,7 @@ namespace WixToolset.Data.WindowsInstaller
155
// parse the child elements
156
if (!empty)
157
{
191
- bool done = false;
158
+ var done = false;
159
160
while (!done && reader.Read())
161
{
src/WixToolset.Data/WindowsInstaller/TableIndexedCollection.cs
+12
-50
@@ -15,19 +15,13 @@ namespace WixToolset.Data.WindowsInstaller
15
/// <summary>
16
/// Instantiate a new empty collection.
17
/// </summary>
18
- public TableIndexedCollection()
19
- {
20
- this.collection = new Dictionary<string, Table>();
21
- }
18
+ public TableIndexedCollection() => this.collection = new Dictionary<string, Table>();
19
20
/// <summary>
21
/// Instantiate a new collection populated with a set of tables.
22
/// </summary>
23
/// <param name="tables">Set of tables.</param>
27
- public TableIndexedCollection(IEnumerable<Table> tables)
28
- {
29
- this.collection = tables.ToDictionary(t => t.Name);
30
- }
24
+ public TableIndexedCollection(IEnumerable<Table> tables) => this.collection = tables.ToDictionary(t => t.Name);
25
26
/// <summary>
27
/// Gets the number of items in the collection.
@@ -45,18 +39,12 @@ namespace WixToolset.Data.WindowsInstaller
39
/// </summary>
40
/// <param name="table">Table to add to the collection.</param>
41
/// <remarks>Indexes the table by name.</remarks>
48
- public void Add(Table table)
49
- {
50
- this.collection.Add(table.Name, table);
51
- }
42
+ public void Add(Table table) => this.collection.Add(table.Name, table);
43
44
/// <summary>
45
/// Clear the tables from the collection.
46
/// </summary>
56
- public void Clear()
57
- {
58
- this.collection.Clear();
59
- }
47
+ public void Clear() => this.collection.Clear();
48
49
/// <summary>
50
/// Determines if a table is in the collection.
@@ -70,46 +58,31 @@ namespace WixToolset.Data.WindowsInstaller
58
/// </summary>
59
/// <param name="array">Array to copy the collection into.</param>
60
/// <param name="arrayIndex">Index to start copying from.</param>
73
- public void CopyTo(Table[] array, int arrayIndex)
74
- {
75
- this.collection.Values.CopyTo(array, arrayIndex);
76
- }
61
+ public void CopyTo(Table[] array, int arrayIndex) => this.collection.Values.CopyTo(array, arrayIndex);
62
63
/// <summary>
64
/// Remove a table from the collection by name.
65
/// </summary>
66
/// <param name="tableName">Table name to remove from the collection.</param>
82
- public void Remove(string tableName)
83
- {
84
- this.collection.Remove(tableName);
85
- }
67
+ public void Remove(string tableName) => _ = this.collection.Remove(tableName);
68
69
/// <summary>
70
/// Remove a table from the collection.
71
/// </summary>
72
/// <param name="table">Table with matching name to remove from the collection.</param>
91
- public bool Remove(Table table)
92
- {
93
- return this.collection.Remove(table.Name);
94
- }
73
+ public bool Remove(Table table) => this.collection.Remove(table.Name);
74
75
/// <summary>
76
/// Gets an enumerator over the whole collection.
77
/// </summary>
78
/// <returns>Collection enumerator.</returns>
100
- public IEnumerator<Table> GetEnumerator()
101
- {
102
- return this.collection.Values.GetEnumerator();
103
- }
79
+ public IEnumerator<Table> GetEnumerator() => this.collection.Values.GetEnumerator();
80
81
/// <summary>
82
/// Gets an untyped enumerator over the whole collection.
83
/// </summary>
84
/// <returns>Untyped collection enumerator.</returns>
109
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
110
- {
111
- return this.collection.Values.GetEnumerator();
112
- }
85
+ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.collection.Values.GetEnumerator();
86
87
/// <summary>
88
/// Gets a table by name.
@@ -117,16 +90,8 @@ namespace WixToolset.Data.WindowsInstaller
90
/// <param name="tableName">Name of table to locate.</param>
91
public Table this[string tableName]
92
{
120
- get
121
- {
122
- Table table;
123
- return this.collection.TryGetValue(tableName, out table) ? table : null;
124
- }
125
-
126
- set
127
- {
128
- this.collection[tableName] = value;
129
- }
93
+ get => this.collection.TryGetValue(tableName, out var table) ? table : null;
94
+ set => this.collection[tableName] = value;
95
}
96
97
/// <summary>
@@ -135,9 +100,6 @@ namespace WixToolset.Data.WindowsInstaller
100
/// <param name="tableName">Table name to locate.</param>
101
/// <param name="table">Found table.</param>
102
/// <returns>True if table with table name was found, otherwise false.</returns>
138
- public bool TryGetTable(string tableName, out Table table)
139
- {
140
- return this.collection.TryGetValue(tableName, out table);
141
- }
103
+ public bool TryGetTable(string tableName, out Table table) => this.collection.TryGetValue(tableName, out table);
104
}
105
}
src/WixToolset.Data/WindowsInstaller/WindowsInstallerData.cs
+36
-31
@@ -60,6 +60,42 @@ namespace WixToolset.Data.WindowsInstaller
60
/// <value>Collection of tables.</value>
61
public TableIndexedCollection Tables { get; private set; }
62
63
+ /// <summary>
64
+ /// Ensure this output contains a particular table.
65
+ /// </summary>
66
+ /// <param name="tableDefinition">Definition of the table that should exist.</param>
67
+ /// <param name="section">Optional section to use for the table. If one is not provided, the entry section will be used.</param>
68
+ /// <returns>The table in this output.</returns>
69
+ public Table EnsureTable(TableDefinition tableDefinition)
70
+ {
71
+ if (!this.Tables.TryGetTable(tableDefinition.Name, out var table))
72
+ {
73
+ table = new Table(tableDefinition);
74
+ this.Tables.Add(table);
75
+ }
76
+
77
+ return table;
78
+ }
79
+
80
+ /// <summary>
81
+ /// Saves an output to a <c>WixOutput</c> container.
82
+ /// </summary>
83
+ /// <param name="wixout">Container to save to.</param>
84
+ public void Save(WixOutput wixout)
85
+ {
86
+ using (var writer = XmlWriter.Create(wixout.CreateDataStream(WixOutputStreamName)))
87
+ {
88
+ writer.WriteStartDocument();
89
+ this.Write(writer);
90
+ writer.WriteEndDocument();
91
+ }
92
+ }
93
+
94
+ /// <summary>
95
+ /// Gets table by name.
96
+ /// </summary>
97
+ public bool TryGetTable(string tableName, out Table table) => this.Tables.TryGetTable(tableName, out table);
98
+
99
/// <summary>
100
/// Loads an output from a path on disk.
101
/// </summary>
@@ -84,20 +120,6 @@ namespace WixToolset.Data.WindowsInstaller
120
}
121
}
122
87
- /// <summary>
88
- /// Saves an output to a <c>WixOutput</c> container.
89
- /// </summary>
90
- /// <param name="wixout">Container to save to.</param>
91
- public void Save(WixOutput wixout)
92
- {
93
- using (var writer = XmlWriter.Create(wixout.CreateDataStream(WixOutputStreamName)))
94
- {
95
- writer.WriteStartDocument();
96
- this.Write(writer);
97
- writer.WriteEndDocument();
98
- }
99
- }
100
-
123
/// <summary>
124
/// Processes an XmlReader and builds up the output object.
125
/// </summary>
@@ -206,23 +228,6 @@ namespace WixToolset.Data.WindowsInstaller
228
return output;
229
}
230
209
- /// <summary>
210
- /// Ensure this output contains a particular table.
211
- /// </summary>
212
- /// <param name="tableDefinition">Definition of the table that should exist.</param>
213
- /// <param name="section">Optional section to use for the table. If one is not provided, the entry section will be used.</param>
214
- /// <returns>The table in this output.</returns>
215
- public Table EnsureTable(TableDefinition tableDefinition)
216
- {
217
- if (!this.Tables.TryGetTable(tableDefinition.Name, out var table))
218
- {
219
- table = new Table(tableDefinition);
220
- this.Tables.Add(table);
221
- }
222
-
223
- return table;
224
- }
225
-
231
/// <summary>
232
/// Persists an output in an XML format.
233
/// </summary>