2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / DateTimeArgBuilder.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Microsoft Public License. A 
6  * copy of the license can be found in the License.html file at the root of this distribution. If 
7  * you cannot locate the  Microsoft Public License, please send an email to 
8  * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
9  * by the terms of the Microsoft Public License.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15 using System; using Microsoft;
16
17
18
19 #if !SILVERLIGHT // ComObject
20
21 using System.Collections.Generic;
22 using System.Diagnostics;
23 #if CODEPLEX_40
24 using System.Linq.Expressions;
25 #else
26 using Microsoft.Linq.Expressions;
27 #endif
28 using System.Runtime.CompilerServices;
29 #if !CODEPLEX_40
30 using Microsoft.Runtime.CompilerServices;
31 #endif
32
33 using System.Runtime.InteropServices;
34 #if CODEPLEX_40
35 using System.Dynamic.Utils;
36 #else
37 using Microsoft.Scripting.Utils;
38 #endif
39
40 #if CODEPLEX_40
41 namespace System.Dynamic {
42 #else
43 namespace Microsoft.Scripting {
44 #endif
45     internal sealed class DateTimeArgBuilder : SimpleArgBuilder {
46         internal DateTimeArgBuilder(Type parameterType)
47             : base(parameterType) {
48             Debug.Assert(parameterType == typeof(DateTime));
49         }
50
51         internal override Expression MarshalToRef(Expression parameter) {
52             // parameter.ToOADate()
53             return Expression.Call(
54                 Marshal(parameter),
55                 typeof(DateTime).GetMethod("ToOADate")
56             );
57         }
58
59         internal override Expression UnmarshalFromRef(Expression value) {
60             // DateTime.FromOADate(value)
61             return base.UnmarshalFromRef(
62                 Expression.Call(
63                     typeof(DateTime).GetMethod("FromOADate"),
64                     value
65                 )
66             );
67         }
68     }
69 }
70
71 #endif