FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScript/HostVariable.cs at master · ExtrieveTechnologies/ClearScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ExtrieveTechnologies
/
ClearScript
Public
forked from
ClearFoundry/ClearScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ClearScript
/
ClearScript
/
HostVariable.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
200 lines (163 loc) · 6 KB
Breadcrumbs
ClearScript
/
ClearScript
/
HostVariable.cs
Copy path
File metadata and controls
200 lines (163 loc) · 6 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
Dynamic
;
using
System
.
Reflection
;
using
Microsoft
.
ClearScript
.
Util
;
namespace
Microsoft
.
ClearScript
{
internal
interface
IHostVariable
{
Type
Type
{
get
;
}
object
Value
{
get
;
set
;
}
}
internal
abstract
class
HostVariableBase
:
HostTarget
{
private
static
readonly
string
[
]
auxPropertyNames
=
{
"out"
,
"ref"
,
"value"
}
;
public
override
string
[
]
GetAuxPropertyNames
(
IHostInvokeContext
context
,
BindingFlags
bindFlags
)
{
return
auxPropertyNames
;
}
}
internal
sealed
class
HostVariable
<
T
>
:
HostVariableBase
,
IHostVariable
{
private
T
value
;
public
HostVariable
(
T
initValue
)
{
if
(
(
typeof
(
T
)
==
typeof
(
Undefined
)
)
||
(
typeof
(
T
)
==
typeof
(
VoidResult
)
)
)
{
throw
new
NotSupportedException
(
"Unsupported variable type"
)
;
}
if
(
typeof
(
HostItem
)
.
IsAssignableFrom
(
typeof
(
T
)
)
||
typeof
(
HostTarget
)
.
IsAssignableFrom
(
typeof
(
T
)
)
)
{
throw
new
NotSupportedException
(
"Unsupported variable type"
)
;
}
if
(
(
initValue
is
HostItem
)
||
(
initValue
is
HostTarget
)
)
{
throw
new
NotSupportedException
(
"Unsupported value type"
)
;
}
value
=
initValue
;
}
public
T
Value
{
// Be careful when renaming or deleting this property; it is accessed by name in the
// expression tree construction code in DelegateFactory.CreateComplexDelegate().
get
{
return
value
;
}
set
{
this
.
value
=
value
;
}
}
#region Object overrides
public
override
string
ToString
(
)
{
var
objectName
=
value
.
GetFriendlyName
(
typeof
(
T
)
)
;
return
MiscHelpers
.
FormatInvariant
(
"HostVariable:{0}"
,
objectName
)
;
}
#endregion
#region HostTarget overrides
public
override
Type
Type
{
get
{
return
typeof
(
T
)
;
}
}
public
override
object
Target
{
get
{
return
value
;
}
}
public
override
object
InvokeTarget
{
get
{
return
value
;
}
}
public
override
object
DynamicInvokeTarget
{
get
{
return
value
;
}
}
public
override
HostTargetFlags
GetFlags
(
IHostInvokeContext
context
)
{
var
flags
=
HostTargetFlags
.
AllowInstanceMembers
|
HostTargetFlags
.
AllowExtensionMethods
;
if
(
context
.
Engine
.
ExposeHostObjectStaticMembers
)
{
flags
|=
HostTargetFlags
.
AllowStaticMembers
;
}
return
flags
;
}
public
override
bool
TryInvokeAuxMember
(
IHostInvokeContext
context
,
string
name
,
BindingFlags
invokeFlags
,
object
[
]
args
,
object
[
]
bindArgs
,
out
object
result
)
{
const
BindingFlags
getPropertyFlags
=
BindingFlags
.
GetField
|
BindingFlags
.
GetProperty
;
const
BindingFlags
setPropertyFlags
=
BindingFlags
.
SetProperty
|
BindingFlags
.
PutDispProperty
|
BindingFlags
.
PutRefDispProperty
;
if
(
name
==
"out"
)
{
if
(
(
invokeFlags
&
getPropertyFlags
)
!=
0
)
{
result
=
new
OutArg
<
T
>
(
this
)
;
return
true
;
}
}
else
if
(
name
==
"ref"
)
{
if
(
(
invokeFlags
&
getPropertyFlags
)
!=
0
)
{
result
=
new
RefArg
<
T
>
(
this
)
;
return
true
;
}
}
else
if
(
name
==
"value"
)
{
if
(
invokeFlags
.
HasFlag
(
BindingFlags
.
InvokeMethod
)
)
{
if
(
InvokeHelpers
.
TryInvokeObject
(
context
,
value
,
invokeFlags
,
args
,
bindArgs
,
typeof
(
IDynamicMetaObjectProvider
)
.
IsAssignableFrom
(
typeof
(
T
)
)
,
out
result
)
)
{
return
true
;
}
if
(
invokeFlags
.
HasFlag
(
BindingFlags
.
GetField
)
&&
(
args
.
Length
<
1
)
)
{
result
=
context
.
Engine
.
PrepareResult
(
value
,
ScriptMemberFlags
.
None
,
false
)
;
return
true
;
}
result
=
null
;
return
false
;
}
if
(
(
invokeFlags
&
getPropertyFlags
)
!=
0
)
{
result
=
context
.
Engine
.
PrepareResult
(
value
,
ScriptMemberFlags
.
None
,
false
)
;
return
true
;
}
if
(
(
invokeFlags
&
setPropertyFlags
)
!=
0
)
{
if
(
args
.
Length
==
1
)
{
result
=
context
.
Engine
.
PrepareResult
(
(
(
IHostVariable
)
this
)
.
Value
=
args
[
0
]
,
typeof
(
T
)
,
ScriptMemberFlags
.
None
,
false
)
;
return
true
;
}
}
}
result
=
null
;
return
false
;
}
public
override
Invocability
GetInvocability
(
BindingFlags
bindFlags
,
Type
accessContext
,
ScriptAccess
defaultAccess
,
bool
ignoreDynamic
)
{
return
typeof
(
T
)
.
GetInvocability
(
bindFlags
,
accessContext
,
defaultAccess
,
ignoreDynamic
)
;
}
#endregion
#region IHostVariable implementation
object
IHostVariable
.
Value
{
get
{
return
value
;
}
set
{
if
(
!
typeof
(
T
)
.
IsAssignableFrom
(
ref
value
)
)
{
throw
new
InvalidOperationException
(
"Assignment invalid due to type mismatch"
)
;
}
if
(
(
value
is
HostItem
)
||
(
value
is
HostTarget
)
)
{
throw
new
NotSupportedException
(
"Unsupported value type"
)
;
}
this
.
value
=
(
T
)
value
;
}
}
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL