Merge pull request #1109 from adbre/iss358
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / ErrorArgBuilder.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 #if !SILVERLIGHT // ComObject
19
20 using System.Collections.Generic;
21 #if CODEPLEX_40
22 using System.Linq.Expressions;
23 #else
24 using Microsoft.Linq.Expressions;
25 #endif
26 using System.Runtime.InteropServices;
27 using System.Diagnostics;
28 #if CODEPLEX_40
29 using System.Dynamic.Utils;
30 #else
31 using Microsoft.Scripting.Utils;
32 #endif
33
34 #if CODEPLEX_40
35 namespace System.Dynamic {
36 #else
37 namespace Microsoft.Scripting {
38 #endif
39     internal class ErrorArgBuilder : SimpleArgBuilder {
40         internal ErrorArgBuilder(Type parameterType)
41             : base(parameterType) {
42
43             Debug.Assert(parameterType == typeof(ErrorWrapper));
44         }
45
46         internal override Expression Marshal(Expression parameter) {
47             // parameter.ErrorCode
48             return Expression.Property(
49                 Helpers.Convert(base.Marshal(parameter), typeof(ErrorWrapper)),
50                 "ErrorCode"
51             );
52         }
53
54         internal override Expression UnmarshalFromRef(Expression value) {
55             // new ErrorWrapper(value)
56             return base.UnmarshalFromRef(
57                 Expression.New(
58                     typeof(ErrorWrapper).GetConstructor(new Type[] { typeof(int) }),
59                     value
60                 )
61             );
62         }
63     }
64 }
65
66 #endif