Skip to content

Commit dec82f6

Browse files
nickeeexjvuoti
authored andcommitted
issue #2 ParseResult ToJson() returns an object instead of a JToken. (#3)
1 parent 80178a8 commit dec82f6

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Frends.Csv.Tests/Frends.Csv.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<Reference Include="CsvHelper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823, processorArchitecture=MSIL">
3939
<HintPath>..\packages\CsvHelper.2.16.3.0\lib\net45\CsvHelper.dll</HintPath>
4040
</Reference>
41+
<Reference Include="Microsoft.CSharp" />
4142
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
4243
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
4344
<Private>True</Private>

Frends.Csv.Tests/Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public void TestParseSkipRowsWithAutomaticHeaders()
2424
Csv = csv
2525
}, new ParseOption() {ContainsHeaderRow = true, SkipRowsFromTop = 2});
2626

27-
var resultJArray = result.ToJson() as JArray;
27+
dynamic resultJArray = result.ToJson();
2828
var resultXml = result.ToXml();
2929
var resultData = result.Data;
3030
Assert.That(resultData.Count, Is.EqualTo(2));
3131
Assert.That(resultJArray.Count, Is.EqualTo(2));
3232
Assert.That(resultXml,Does.Contain("<year>2000</year>"));
33-
Assert.That(resultJArray[0]["price"].Value<string>(), Is.EqualTo("2,34"));
33+
Assert.That(resultJArray[0].price.ToString(), Is.EqualTo("2,34"));
3434
}
3535

3636
[Test]

Frends.Csv/Definitions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,15 @@ public class ParseOption
142142

143143
public class ParseResult
144144
{
145-
private readonly Lazy<JToken> _jToken;
145+
private readonly Lazy<object> _jToken;
146146
private readonly Lazy<string> _xml;
147147
private static CultureInfo _culture;
148148
public ParseResult(List<List<object>> data, List<string> headers, CultureInfo configurationCultureInfo)
149149
{
150150
Data = data;
151151
Headers = headers;
152152
_culture = configurationCultureInfo;
153-
_jToken = new Lazy<JToken>(() => Data != null ? WriteJToken(data,headers) : null);
153+
_jToken = new Lazy<object>(() => Data != null ? WriteJToken(data,headers) : null);
154154
_xml = new Lazy<string>(() => Data != null ? WriteXmlString(data, headers) : null);
155155
}
156156

@@ -179,7 +179,7 @@ private static string WriteXmlString(IEnumerable<List<object>> data, IReadOnlyLi
179179
}
180180
}
181181

182-
private static JToken WriteJToken(IEnumerable<List<object>> data, IReadOnlyList<string> headers)
182+
private static object WriteJToken(IEnumerable<List<object>> data, IReadOnlyList<string> headers)
183183
{
184184
using (var writer = new JTokenWriter())
185185
{
@@ -204,7 +204,7 @@ private static JToken WriteJToken(IEnumerable<List<object>> data, IReadOnlyList<
204204

205205
public List<List<object>> Data { get; }
206206
public List<string> Headers { get; set; }
207-
public JToken ToJson()
207+
public object ToJson()
208208
{
209209
return _jToken.Value;
210210
}

0 commit comments

Comments
 (0)