Skip to content

Commit 2df78e7

Browse files
committed
Merge branch 'steffanv-master'
2 parents 991ad2d + 9c9de2b commit 2df78e7

Some content is hidden

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

46 files changed

+311
-296
lines changed

FileHelpers.Examples/Examples/18.Converters/60.CustomConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class MoneyConverter : ConverterBase
4545
{
4646
public override object StringToField(string from)
4747
{
48-
return Convert.ToDecimal(Decimal.Parse(from) / 100);
48+
return Convert.ToDecimal(decimal.Parse(from) / 100);
4949
}
5050

5151
public override string FieldToString(object fieldValue)

FileHelpers.Examples/Examples/50.Advanced/30.MultiRecordEngine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private Type CustomSelector(MultiRecordEngine engine, string recordLine)
137137
if (recordLine.Length == 0)
138138
return null;
139139

140-
if (Char.IsLetter(recordLine[0]))
140+
if (char.IsLetter(recordLine[0]))
141141
return typeof (Customer);
142142
else if (recordLine.Length == 14)
143143
return typeof (SampleType);

FileHelpers.Examples/Examples/90.MasterDetail/10.MasterDetailCustomSelector.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private RecordAction ExampleSelector(string record)
3838
if (record.Length < 2)
3939
return RecordAction.Skip;
4040

41-
if (Char.IsLetter(record[0]))
41+
if (char.IsLetter(record[0]))
4242
return RecordAction.Master;
4343
else
4444
return RecordAction.Detail;

FileHelpers.ExcelNPOIStorage/ExcelNPOIStorage.cs

+15-23
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ namespace FileHelpers.ExcelNPOIStorage
2424
public sealed class ExcelNPOIStorage : ExcelStorageBase
2525
#pragma warning restore 618
2626
{
27-
//private readonly Missing mv = Missing.Value;
28-
2927
#region " Constructors "
3028

3129
/// <summary>Create a new ExcelStorage to work with the specified type</summary>
@@ -85,7 +83,7 @@ private void CloseAndCleanUp()
8583

8684
#endregion
8785

88-
#region " OpenWorkbook "
86+
#region " OpenWorkbookFromStream "
8987

9088
private void OpenWorkbook(string filename)
9189
{
@@ -95,17 +93,19 @@ private void OpenWorkbook(string filename)
9593

9694
using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read))
9795
{
98-
var extension = Path.GetExtension(filename);
99-
OpenWorkbook(file, extension);
96+
OpenWorkbookFromStream(file);
10097
}
10198
}
10299

103-
private void OpenWorkbook(Stream stream, string knownFileExtension = null)
100+
private void OpenWorkbookFromStream(Stream stream)
104101
{
105102
mWorkbook = WorkbookFactory.Create(stream);
103+
mWorkbook.MissingCellPolicy = MissingCellPolicy.CREATE_NULL_AS_BLANK;
106104

107-
if (String.IsNullOrEmpty(SheetName))
105+
if (string.IsNullOrEmpty(SheetName))
106+
{
108107
mSheet = mWorkbook.GetSheetAt(mWorkbook.ActiveSheetIndex);
108+
}
109109
else
110110
{
111111
try
@@ -150,7 +150,7 @@ private void CreateWorkbook(string filename)
150150
mWorkbook = new XSSFWorkbook();
151151
else if (extension.ToLowerInvariant() == ".xls")
152152
mWorkbook = new HSSFWorkbook();
153-
mSheet = mSheet = String.IsNullOrEmpty(SheetName) ? mWorkbook.CreateSheet() : mWorkbook.CreateSheet(SheetName);
153+
mSheet = mSheet = string.IsNullOrEmpty(SheetName) ? mWorkbook.CreateSheet() : mWorkbook.CreateSheet(SheetName);
154154
mWorkbook.SetActiveSheet(0);
155155
}
156156

@@ -336,12 +336,12 @@ public override void InsertRecords(object[] records)
336336
if (OverrideFile && File.Exists(FileName))
337337
File.Delete(FileName);
338338

339-
if (!String.IsNullOrEmpty(TemplateFile))
339+
if (!string.IsNullOrEmpty(TemplateFile))
340340
{
341341
if (File.Exists(TemplateFile) == false)
342342
throw new ExcelBadUsageException(string.Concat("Template file not found: '", TemplateFile, "'"));
343343

344-
if (String.Compare(TemplateFile, FileName, StringComparison.OrdinalIgnoreCase) != 0)
344+
if (string.Compare(TemplateFile, FileName, StringComparison.OrdinalIgnoreCase) != 0)
345345
File.Copy(TemplateFile, FileName, true);
346346
}
347347

@@ -359,10 +359,6 @@ public override void InsertRecords(object[] records)
359359

360360
SaveWorkbook(FileName);
361361
}
362-
catch
363-
{
364-
throw;
365-
}
366362
finally
367363
{
368364
CloseAndCleanUp();
@@ -378,7 +374,7 @@ public override void InsertRecords(object[] records)
378374
/// <returns>The extracted records.</returns>
379375
public override object[] ExtractRecords()
380376
{
381-
if (String.IsNullOrEmpty(FileName))
377+
if (string.IsNullOrEmpty(FileName))
382378
throw new ExcelBadUsageException("You need to specify the WorkBookFile of the ExcelDataLink.");
383379

384380
return TryGetRecordsFromWorkbook(() => OpenWorkbook(FileName));
@@ -393,7 +389,7 @@ public object[] ExtractRecords(Stream stream)
393389
throw new ArgumentNullException("stream");
394390
}
395391

396-
return TryGetRecordsFromWorkbook(() => OpenWorkbook(stream));
392+
return TryGetRecordsFromWorkbook(() => OpenWorkbookFromStream(stream));
397393
}
398394

399395
private object[] TryGetRecordsFromWorkbook(Action workbookOpenerProvider)
@@ -448,10 +444,6 @@ private object[] TryGetRecordsFromWorkbook(Action workbookOpenerProvider)
448444
}
449445
}
450446
}
451-
catch
452-
{
453-
throw;
454-
}
455447
finally
456448
{
457449
CloseAndCleanUp();
@@ -476,7 +468,7 @@ private static string ColumnsToValues(object[] values)
476468
for (int i = 1; i < values.Length; i++)
477469
{
478470
res += "," + (values[i] == null
479-
? String.Empty
471+
? string.Empty
480472
: values[i].ToString());
481473
}
482474

@@ -485,7 +477,7 @@ private static string ColumnsToValues(object[] values)
485477

486478
private class CellExtractor : ICellHandler
487479
{
488-
private List<object> _cells;
480+
private readonly List<object> _cells;
489481

490482
/// <summary>
491483
/// Initializes a new instance of the CellExtractor class.
@@ -512,7 +504,7 @@ public void OnCell(ICell cell, ICellWalkContext ctx)
512504

513505
private class CellInserter : ICellHandler
514506
{
515-
private List<object> _cells = null;
507+
private readonly List<object> _cells;
516508
private List<object>.Enumerator _valuesEnumerator;
517509

518510
/// <summary>

FileHelpers.ExcelNPOIStorage/NPOIUtils.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public static void SetCellValue(ICell cell, object value)
4646
cell.SetCellValue(null as string);
4747

4848
else if (value is string ||
49-
value is String)
49+
value is string)
5050
cell.SetCellValue(value as string);
5151

5252
else if (value is bool ||
53-
value is Boolean)
53+
value is bool)
5454
cell.SetCellValue((bool) value);
5555

5656
else if (value is DateTime) {
Binary file not shown.

FileHelpers.Tests/FileHelpers.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@
386386
<Content Include="Data\Excel\ExcelWithNoEmptyRows.xlsx" />
387387
<Content Include="Data\Excel\ExcelWithOneEmptyRows.xlsx" />
388388
<Content Include="Data\Excel\ExcelWithTwoEmptyRows.xlsx" />
389+
<None Include="Data\Excel\ExcelWithEmptyCells.xlsx" />
389390
<None Include="FileHelpers.snk" />
390391
<None Include="Data\Good\EncodingChinese.bin" />
391392
<Compile Include="Tests\Detector\HeaderDetection.cs" />

FileHelpers.Tests/Helpers/CompareObjects.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class CompareObjects
5757
{
5858
#region Class Variables
5959

60-
private List<String> _differences = new List<String>();
60+
private List<string> _differences = new List<string>();
6161
private readonly List<object> _parents = new List<object>();
6262
private List<string> _elementsToIgnore = new List<string>();
6363
private bool _comparePrivateProperties = false;
@@ -155,7 +155,7 @@ public int MaxDifferences
155155
/// <summary>
156156
/// The differences found during the compare
157157
/// </summary>
158-
public List<String> Differences
158+
public List<string> Differences
159159
{
160160
get { return _differences; }
161161
set { _differences = value; }
@@ -736,11 +736,11 @@ private bool IsValidIndexer(PropertyInfo info, object object1, object object2, s
736736
return false;
737737
else if (indexers.Length > 1)
738738
throw new Exception("Cannot compare objects with more than one indexer for object " + breadCrumb);
739-
else if (indexers[0].ParameterType != typeof (Int32))
739+
else if (indexers[0].ParameterType != typeof (int))
740740
throw new Exception("Cannot compare objects with a non integer indexer for object " + breadCrumb);
741741
else if (info.ReflectedType.GetProperty("Count") == null)
742742
throw new Exception("Indexer must have a corresponding Count property for object " + breadCrumb);
743-
else if (info.ReflectedType.GetProperty("Count").PropertyType != typeof (Int32)) {
743+
else if (info.ReflectedType.GetProperty("Count").PropertyType != typeof (int)) {
744744
throw new Exception("Indexer must have a corresponding Count property that is an integer for object " +
745745
breadCrumb);
746746
}
@@ -925,7 +925,7 @@ private void CompareIList(object object1, object object2, string breadCrumb)
925925
/// <returns></returns>
926926
private string AddBreadCrumb(string existing, string name, string extra, string index)
927927
{
928-
bool useIndex = !String.IsNullOrEmpty(index);
928+
bool useIndex = !string.IsNullOrEmpty(index);
929929
bool useName = name.Length > 0;
930930
var sb = new StringBuilder();
931931

@@ -940,7 +940,7 @@ private string AddBreadCrumb(string existing, string name, string extra, string
940940

941941
if (useIndex) {
942942
int result = -1;
943-
if (Int32.TryParse(index, out result))
943+
if (int.TryParse(index, out result))
944944
sb.AppendFormat("[{0}]", index);
945945
else
946946
sb.AppendFormat("[\"{0}\"]", index);

FileHelpers.Tests/Tests/Common/Converters.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,40 @@ public sealed class AllConvertersType
3737
public DateTime Field2;
3838

3939
[FieldConverter(ConverterKind.Byte)]
40-
public Byte Field3;
40+
public byte Field3;
4141

4242
[FieldConverter(ConverterKind.SByte)]
43-
public SByte Field4;
43+
public sbyte Field4;
4444

4545
[FieldConverter(ConverterKind.Int16)]
46-
public Int16 Field5;
46+
public short Field5;
4747

4848
[FieldConverter(ConverterKind.Int32)]
49-
public Int32 Field6;
49+
public int Field6;
5050

5151
[FieldConverter(ConverterKind.Int64)]
52-
public Int64 Field7;
52+
public long Field7;
5353

5454
[FieldConverter(ConverterKind.UInt16)]
55-
public UInt16 Field8;
55+
public ushort Field8;
5656

5757
[FieldConverter(ConverterKind.UInt32)]
58-
public UInt32 Field9;
58+
public uint Field9;
5959

6060
[FieldConverter(ConverterKind.UInt64)]
61-
public UInt64 Field10;
61+
public ulong Field10;
6262

6363
[FieldConverter(ConverterKind.Decimal)]
64-
public Decimal Field11;
64+
public decimal Field11;
6565

6666
[FieldConverter(ConverterKind.Double)]
67-
public Double Field12;
67+
public double Field12;
6868

6969
[FieldConverter(ConverterKind.Single)]
70-
public Single Field13;
70+
public float Field13;
7171

7272
[FieldConverter(ConverterKind.Boolean)]
73-
public Boolean Field14;
73+
public bool Field14;
7474
}
7575

7676
// NUNIT TESTS

FileHelpers.Tests/Tests/Common/EncodingAdv.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public void GetMSWSReportsFromFile_20060720_32Records()
2929
public sealed class MSWSDailyReportRecord
3030
{
3131
[FieldFixedLength(26)]
32-
public String Location;
32+
public string Location;
3333

3434
[FieldFixedLength(12)]
35-
public String County;
35+
public string County;
3636

3737
[FieldFixedLength(5)]
3838
public int Elev;

FileHelpers.Tests/Tests/Common/FieldDelimited.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public void CustomDelimiter()
2424
private class SOXLog
2525
{
2626
[FieldDelimiter(": ")]
27-
internal String DummyField;
27+
internal string DummyField;
2828

2929
public ActionEnum ActionType;
30-
public String TimeStamp;
31-
public String FileName;
30+
public string TimeStamp;
31+
public string FileName;
3232
}
3333

3434
/// <summary>

FileHelpers.Tests/Tests/Common/FileEncodingAdvanced.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public void EncodingAdvanced5()
7171
public sealed class EncodingRecord
7272
{
7373
[FieldFixedLength(26)]
74-
public String Location;
74+
public string Location;
7575

7676
[FieldFixedLength(12)]
77-
public String County;
77+
public string County;
7878

7979
[FieldFixedLength(5)]
8080
public int Elev;

FileHelpers.Tests/Tests/Common/ImageConvertion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class ImageConverter : ConverterBase
7373
{
7474
public override object StringToField(string from)
7575
{
76-
Byte[] bitmapData;
76+
byte[] bitmapData;
7777
bitmapData = Convert.FromBase64String(from);
7878
var streamBitmap = new MemoryStream(bitmapData);
7979
return Image.FromStream(streamBitmap);

FileHelpers.Tests/Tests/Common/InheritedTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,14 @@ public class MoneyConverter : ConverterBase
142142

143143
public override string FieldToString(object from)
144144
{
145-
Decimal v = Convert.ToDecimal(from);
145+
decimal v = Convert.ToDecimal(from);
146146
v *= (10 ^ DECIMAL_PLACES);
147147
return Convert.ToInt64(v).ToString();
148148
}
149149

150150
public override object StringToField(string from)
151151
{
152-
return Convert.ToDecimal(Decimal.Parse(from)/(10 ^ DECIMAL_PLACES));
152+
return Convert.ToDecimal(decimal.Parse(from)/(10 ^ DECIMAL_PLACES));
153153
}
154154
}
155155

0 commit comments

Comments
 (0)