Code Coverage Statistics for Source File
Newtonsoft.Json\Utilities\ReflectionDelegateFactory.cs
Symbol Coverage: 87.50% (14 of 16)
Branch Coverage: 77.78% (7 of 9)
Cyclomatic Complexity Avg: 2.33 Max:3
Code Lines: 16
Symbol Coverage Trend
View:
L | V | Source |
---|---|---|
1 |
#region License |
|
2 |
// Copyright (c) 2007 James Newton-King |
|
3 |
// |
|
4 |
// Permission is hereby granted, free of charge, to any person |
|
5 |
// obtaining a copy of this software and associated documentation |
|
6 |
// files (the "Software"), to deal in the Software without |
|
7 |
// restriction, including without limitation the rights to use, |
|
8 |
// copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
// copies of the Software, and to permit persons to whom the |
|
10 |
// Software is furnished to do so, subject to the following |
|
11 |
// conditions: |
|
12 |
// |
|
13 |
// The above copyright notice and this permission notice shall be |
|
14 |
// included in all copies or substantial portions of the Software. |
|
15 |
// |
|
16 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
// OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
#endregion |
|
25 |
||
26 |
using System; |
|
27 |
using System.Globalization; |
|
28 |
using System.Reflection; |
|
29 |
||
30 |
namespace Newtonsoft.Json.Utilities |
|
31 |
{ |
|
32 |
internal abstract class ReflectionDelegateFactory |
|
33 |
{ |
|
34 |
public Func<T, object> CreateGet<T>(MemberInfo memberInfo) |
|
35 |
{ |
|
36 |
375 |
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
|
37 |
375 |
if (propertyInfo != null)
|
38 |
274 |
return CreateGet<T>(propertyInfo);
|
39 |
||
40 |
101 |
FieldInfo fieldInfo = memberInfo as FieldInfo;
|
41 |
101 |
if (fieldInfo != null)
|
42 |
101 |
return CreateGet<T>(fieldInfo);
|
43 |
||
44 |
0 |
throw new Exception("Could not create getter for {0}.".FormatWith(CultureInfo.InvariantCulture, memberInfo));
|
45 |
375 |
}
|
46 |
||
47 |
public Action<T, object> CreateSet<T>(MemberInfo memberInfo) |
|
48 |
{ |
|
49 |
284 |
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
|
50 |
284 |
if (propertyInfo != null)
|
51 |
193 |
return CreateSet<T>(propertyInfo);
|
52 |
||
53 |
91 |
FieldInfo fieldInfo = memberInfo as FieldInfo;
|
54 |
91 |
if (fieldInfo != null)
|
55 |
91 |
return CreateSet<T>(fieldInfo);
|
56 |
||
57 |
0 |
throw new Exception("Could not create setter for {0}.".FormatWith(CultureInfo.InvariantCulture, memberInfo));
|
58 |
284 |
}
|
59 |
||
60 |
public abstract MethodCall<T, object> CreateMethodCall<T>(MethodBase method); |
|
61 |
public abstract Func<T> CreateDefaultConstructor<T>(Type type); |
|
62 |
public abstract Func<T, object> CreateGet<T>(PropertyInfo propertyInfo); |
|
63 |
public abstract Func<T, object> CreateGet<T>(FieldInfo fieldInfo); |
|
64 |
public abstract Action<T, object> CreateSet<T>(FieldInfo fieldInfo); |
|
65 |
public abstract Action<T, object> CreateSet<T>(PropertyInfo propertyInfo); |
|
66 |
} |
|
67 |
} |