Code Coverage Statistics for Source File
Newtonsoft.Json\JsonConverterAttribute.cs
Symbol Coverage: 72.73% (8 of 11)
Branch Coverage: 66.67% (4 of 6)
Cyclomatic Complexity Avg: 1.33 Max:2
Code Lines: 10
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.Utilities; |
|
6 |
using System.Globalization; |
|
7 |
||
8 |
namespace Newtonsoft.Json |
|
9 |
{ |
|
10 |
/// <summary> |
|
11 |
/// Instructs the <see cref="JsonSerializer"/> to use the specified <see cref="JsonConverter"/> when serializing the member or class. |
|
12 |
/// </summary> |
|
13 |
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false)] |
|
14 |
public sealed class JsonConverterAttribute : Attribute |
|
15 |
{ |
|
16 |
private readonly Type _converterType; |
|
17 |
||
18 |
/// <summary> |
|
19 |
/// Gets the type of the converter. |
|
20 |
/// </summary> |
|
21 |
/// <value>The type of the converter.</value> |
|
22 |
public Type ConverterType |
|
23 |
{ |
|
24 |
8 |
get { return _converterType; }
|
25 |
} |
|
26 |
||
27 |
/// <summary> |
|
28 |
/// Initializes a new instance of the <see cref="JsonConverterAttribute"/> class. |
|
29 |
/// </summary> |
|
30 |
/// <param name="converterType">Type of the converter.</param> |
|
31 |
16 |
public JsonConverterAttribute(Type converterType)
|
32 |
{ |
|
33 |
16 |
if (converterType == null)
|
34 |
0 |
throw new ArgumentNullException("converterType");
|
35 |
||
36 |
16 |
_converterType = converterType;
|
37 |
16 |
}
|
38 |
||
39 |
internal static JsonConverter CreateJsonConverterInstance(Type converterType) |
|
40 |
{ |
|
41 |
try |
|
42 |
{ |
|
43 |
13 |
return (JsonConverter)Activator.CreateInstance(converterType);
|
44 |
} |
|
45 |
0 |
catch (Exception ex)
|
46 |
{ |
|
47 |
0 |
throw new Exception("Error creating {0}".FormatWith(CultureInfo.InvariantCulture, converterType), ex);
|
48 |
} |
|
49 |
13 |
}
|
50 |
} |
|
51 |
} |