Code Coverage Statistics for Source File
Newtonsoft.Json\Utilities\ILGeneratorExtensions.cs
Symbol Coverage: 100.00% (19 of 19)
Branch Coverage: 100.00% (11 of 11)
Cyclomatic Complexity Avg: 2.00 Max:3
Code Lines: 19
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 |
#if !PocketPC && !SILVERLIGHT |
|
27 |
using System; |
|
28 |
using System.Collections.Generic; |
|
29 |
using System.Linq; |
|
30 |
using System.Reflection.Emit; |
|
31 |
using System.Text; |
|
32 |
using System.Reflection; |
|
33 |
||
34 |
namespace Newtonsoft.Json.Utilities |
|
35 |
{ |
|
36 |
internal static class ILGeneratorExtensions |
|
37 |
{ |
|
38 |
public static void PushInstance(this ILGenerator generator, Type type) |
|
39 |
{ |
|
40 |
665 |
generator.Emit(OpCodes.Ldarg_0);
|
41 |
665 |
if (type.IsValueType)
|
42 |
9 |
generator.Emit(OpCodes.Unbox, type);
|
43 |
else |
|
44 |
656 |
generator.Emit(OpCodes.Castclass, type);
|
45 |
665 |
}
|
46 |
||
47 |
public static void BoxIfNeeded(this ILGenerator generator, Type type) |
|
48 |
{ |
|
49 |
389 |
if (type.IsValueType)
|
50 |
149 |
generator.Emit(OpCodes.Box, type);
|
51 |
else |
|
52 |
240 |
generator.Emit(OpCodes.Castclass, type);
|
53 |
389 |
}
|
54 |
||
55 |
public static void UnboxIfNeeded(this ILGenerator generator, Type type) |
|
56 |
{ |
|
57 |
303 |
if (type.IsValueType)
|
58 |
115 |
generator.Emit(OpCodes.Unbox_Any, type);
|
59 |
else |
|
60 |
188 |
generator.Emit(OpCodes.Castclass, type);
|
61 |
303 |
}
|
62 |
||
63 |
public static void CallMethod(this ILGenerator generator, MethodInfo methodInfo) |
|
64 |
{ |
|
65 |
475 |
if (methodInfo.IsFinal || !methodInfo.IsVirtual)
|
66 |
449 |
generator.Emit(OpCodes.Call, methodInfo);
|
67 |
else |
|
68 |
26 |
generator.Emit(OpCodes.Callvirt, methodInfo);
|
69 |
475 |
}
|
70 |
||
71 |
public static void Return(this ILGenerator generator) |
|
72 |
{ |
|
73 |
931 |
generator.Emit(OpCodes.Ret);
|
74 |
931 |
}
|
75 |
} |
|
76 |
} |
|
77 |
#endif |