forked from microsoft/referencesource
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpConvertBinder.cs
More file actions
67 lines (60 loc) · 2.61 KB
/
CSharpConvertBinder.cs
File metadata and controls
67 lines (60 loc) · 2.61 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
59
60
61
62
63
64
65
66
67
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
using System;
using System.ComponentModel;
using System.Dynamic;
namespace Microsoft.CSharp.RuntimeBinder
{
/// <summary>
/// Represents a dynamic conversion in C#, providing the binding semantics and the details about the operation.
/// Instances of this class are generated by the C# compiler.
/// </summary>
internal sealed class CSharpConvertBinder : ConvertBinder
{
internal CSharpConversionKind ConversionKind { get { return m_conversionKind; } }
private CSharpConversionKind m_conversionKind;
internal bool IsChecked { get { return m_isChecked; } }
private bool m_isChecked;
internal Type CallingContext { get { return m_callingContext; } }
private Type m_callingContext;
private RuntimeBinder m_binder;
/// <summary>
/// Initializes a new intsance of the <see cref="CSharpConvertBinder" />.
/// </summary>
/// <param name="type">The type to convert to.</param>
/// <param name="conversionKind">The kind of conversion for this operation.</param>
/// <param name="isChecked">True if the operation is defined in a checked context; otherwise false.</param>
public CSharpConvertBinder(
Type type,
CSharpConversionKind conversionKind,
bool isChecked,
Type callingContext) :
base(type, conversionKind == CSharpConversionKind.ExplicitConversion)
{
m_conversionKind = conversionKind;
m_isChecked = isChecked;
m_callingContext = callingContext;
m_binder = RuntimeBinder.GetInstance();
}
/// <summary>
/// Performs the binding of the dynamic convert operation if the target dynamic object cannot bind.
/// </summary>
/// <param name="target">The target of the dynamic convert operation.</param>
/// <param name="errorSuggestion">The binding result to use if binding fails, or null.</param>
/// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
public override DynamicMetaObject FallbackConvert(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
{
#if !SILVERLIGHT
DynamicMetaObject com;
if (!BinderHelper.IsWindowsRuntimeObject(target) && ComBinder.TryConvert(this, target, out com))
{
return com;
}
#endif
return BinderHelper.Bind(this, m_binder, new[] { target }, null, errorSuggestion);
}
}
}