Code Coverage Statistics for Source File
Newtonsoft.Json.Tests\LinqToSql\DepartmentConverter.cs
Symbol Coverage: 100.00% (14 of 14)
Branch Coverage: 100.00% (4 of 4)
Cyclomatic Complexity Avg: 1.00 Max:1
Code Lines: 14
Symbol Coverage Trend
View:
L | V | Source |
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using Newtonsoft.Json.Linq; |
|
6 |
||
7 |
namespace Newtonsoft.Json.Tests.LinqToSql |
|
8 |
{ |
|
9 |
public class DepartmentConverter : JsonConverter |
|
10 |
{ |
|
11 |
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) |
|
12 |
{ |
|
13 |
1 |
Department department = (Department)value;
|
14 |
||
15 |
1 |
JObject o = new JObject();
|
16 |
1 |
o["DepartmentId"] = new JValue(department.DepartmentId.ToString());
|
17 |
1 |
o["Name"] = new JValue(new string(department.Name.Reverse().ToArray()));
|
18 |
||
19 |
1 |
o.WriteTo(writer);
|
20 |
1 |
}
|
21 |
||
22 |
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) |
|
23 |
{ |
|
24 |
1 |
JObject o = JObject.Load(reader);
|
25 |
||
26 |
1 |
Department department = new Department();
|
27 |
1 |
department.DepartmentId = new Guid((string)o["DepartmentId"]);
|
28 |
1 |
department.Name = new string(((string) o["Name"]).Reverse().ToArray());
|
29 |
||
30 |
1 |
return department;
|
31 |
1 |
}
|
32 |
||
33 |
public override bool CanConvert(Type objectType) |
|
34 |
{ |
|
35 |
1 |
return (objectType == typeof (Department));
|
36 |
1 |
}
|
37 |
} |
|
38 |
} |