FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ClearScript/ClearScript/HostObject.cs at master · killvxk/ClearScript · GitHub
killvxk
/
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
/
HostObject.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
154 lines (114 loc) · 3.92 KB
Breadcrumbs
ClearScript
/
ClearScript
/
HostObject.cs
Copy path
File metadata and controls
154 lines (114 loc) · 3.92 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using
System
;
using
System
.
Reflection
;
using
Microsoft
.
ClearScript
.
Util
;
namespace
Microsoft
.
ClearScript
{
internal
sealed
class
HostObject
:
HostTarget
{
#region data
private
readonly
object
target
;
private
readonly
Type
type
;
private
static
readonly
MethodInfo
getNullWrapperGenericMethod
=
typeof
(
HostObject
)
.
GetMethod
(
"GetNullWrapperGeneric"
,
BindingFlags
.
NonPublic
|
BindingFlags
.
Static
)
;
#endregion
#region constructors
private
HostObject
(
object
target
,
Type
type
)
{
this
.
target
=
CanonicalRefTable
.
GetCanonicalRef
(
target
)
;
this
.
type
=
type
??
target
.
GetType
(
)
;
}
#endregion
#region wrappers
public
static
HostObject
Wrap
(
object
target
)
{
return
Wrap
(
target
,
null
)
;
}
public
static
HostObject
Wrap
(
object
target
,
Type
type
)
{
return
(
target
!=
null
)
?
new
HostObject
(
target
,
type
)
:
null
;
}
public
static
object
WrapResult
(
object
result
,
Type
type
,
bool
wrapNull
)
{
if
(
(
result
is
HostItem
)
||
(
result
is
HostTarget
)
)
{
return
result
;
}
if
(
result
==
null
)
{
return
wrapNull
?
GetNullWrapper
(
type
)
:
null
;
}
if
(
(
type
==
typeof
(
void
)
)
||
(
type
==
typeof
(
object
)
)
||
type
.
IsNullable
(
)
)
{
return
result
;
}
if
(
(
type
==
result
.
GetType
(
)
)
||
(
Type
.
GetTypeCode
(
type
)
!=
TypeCode
.
Object
)
)
{
return
result
;
}
return
Wrap
(
result
,
type
)
;
}
#endregion
#region internal members
private
static
HostObject
GetNullWrapper
(
Type
type
)
{
return
(
HostObject
)
getNullWrapperGenericMethod
.
MakeGenericMethod
(
type
)
.
Invoke
(
null
,
ArrayHelpers
.
GetEmptyArray
<
object
>
(
)
)
;
}
// ReSharper disable UnusedMember.Local
private
static
HostObject
GetNullWrapperGeneric
<
T
>
(
)
{
return
NullWrapper
<
T
>
.
Value
;
}
// ReSharper restore UnusedMember.Local
#endregion
#region Object overrides
public
override
string
ToString
(
)
{
if
(
(
target
is
ScriptItem
)
&&
(
typeof
(
ScriptItem
)
.
IsAssignableFrom
(
type
)
)
)
{
return
"ScriptItem"
;
}
var
objectName
=
target
.
GetFriendlyName
(
type
)
;
return
MiscHelpers
.
FormatInvariant
(
"HostObject:{0}"
,
objectName
)
;
}
#endregion
#region HostTarget overrides
public
override
Type
Type
{
get
{
return
type
;
}
}
public
override
object
Target
{
get
{
return
target
;
}
}
public
override
object
InvokeTarget
{
get
{
return
target
;
}
}
public
override
object
DynamicInvokeTarget
{
get
{
return
target
;
}
}
public
override
HostTargetFlags
Flags
{
get
{
return
HostTargetFlags
.
AllowInstanceMembers
|
HostTargetFlags
.
AllowExtensionMethods
;
}
}
public
override
Invocability
GetInvocability
(
BindingFlags
bindFlags
,
Type
accessContext
,
ScriptAccess
defaultAccess
,
bool
ignoreDynamic
)
{
return
type
.
GetInvocability
(
bindFlags
,
accessContext
,
defaultAccess
,
ignoreDynamic
)
;
}
#endregion
#region Nested type: NullWrapper<T>
// ReSharper disable UnusedMember.Local
private
static
class
NullWrapper
<
T
>
{
private
static
readonly
HostObject
value
=
new
HostObject
(
null
,
typeof
(
T
)
)
;
public
static
HostObject
Value
{
get
{
return
value
;
}
}
}
// ReSharper restore UnusedMember.Local
#endregion
}
}
Back
|
FazBrowse Home
|
New Git URL