forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrencyArgBuilder.cs
More file actions
59 lines (52 loc) · 1.75 KB
/
Copy pathCurrencyArgBuilder.cs
File metadata and controls
59 lines (52 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
#if !SILVERLIGHT // ComObject
#if !CLR2
using System.Linq.Expressions;
#else
using Microsoft.Scripting.Ast;
#endif
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace System.Management.Automation.ComInterop
{
internal sealed class CurrencyArgBuilder : SimpleArgBuilder
{
internal CurrencyArgBuilder(Type parameterType)
: base(parameterType)
{
Debug.Assert(parameterType == typeof(CurrencyWrapper));
}
internal override Expression Marshal(Expression parameter)
{
// parameter.WrappedObject
return Expression.Property(
Helpers.Convert(base.Marshal(parameter), typeof(CurrencyWrapper)),
"WrappedObject"
);
}
internal override Expression MarshalToRef(Expression parameter)
{
// Decimal.ToOACurrency(parameter.WrappedObject)
return Expression.Call(
typeof(Decimal).GetMethod("ToOACurrency"),
Marshal(parameter)
);
}
internal override Expression UnmarshalFromRef(Expression value)
{
// Decimal.FromOACurrency(value)
return base.UnmarshalFromRef(
Expression.New(
typeof(CurrencyWrapper).GetConstructor(new Type[] { typeof(Decimal) }),
Expression.Call(
typeof(Decimal).GetMethod("FromOACurrency"),
value
)
)
);
}
}
}
#endif