1
1
#if ! NETSTANDARD
2
2
using System ;
3
3
using System . Globalization ;
4
- using System . Linq ;
5
4
using System . Reflection ;
6
5
6
+ using MsieJavaScriptEngine . Helpers ;
7
+
7
8
namespace MsieJavaScriptEngine
8
9
{
9
10
/// <summary>
@@ -22,7 +23,7 @@ internal abstract class HostItemBase : IReflect
22
23
protected readonly object _target ;
23
24
24
25
/// <summary>
25
- /// JavaScript engine mode
26
+ /// JS engine mode
26
27
/// </summary>
27
28
protected readonly JsEngineMode _engineMode ;
28
29
@@ -31,6 +32,11 @@ internal abstract class HostItemBase : IReflect
31
32
/// </summary>
32
33
private readonly FieldInfo [ ] _fields ;
33
34
35
+ /// <summary>
36
+ /// List of field names
37
+ /// </summary>
38
+ private string [ ] _fieldNames ;
39
+
34
40
/// <summary>
35
41
/// List of properties
36
42
/// </summary>
@@ -63,19 +69,18 @@ protected HostItemBase(Type type, object target, JsEngineMode engineMode, bool i
63
69
_target = target ;
64
70
_engineMode = engineMode ;
65
71
66
- BindingFlags bindingFlags = BindingFlags . Public ;
67
- if ( instance )
68
- {
69
- bindingFlags |= BindingFlags . Instance ;
70
- }
71
- else
72
- {
73
- bindingFlags |= BindingFlags . Static ;
74
- }
75
-
76
- _fields = _type . GetFields ( bindingFlags ) ;
77
- _properties = _type . GetProperties ( bindingFlags ) ;
78
- _methods = _type . GetMethods ( bindingFlags ) ;
72
+ BindingFlags defaultBindingFlags = ReflectionHelpers . GetDefaultBindingFlags ( instance ) ;
73
+ FieldInfo [ ] fields = _type . GetFields ( defaultBindingFlags ) ;
74
+ string [ ] fieldNames = fields . Length > 0 ? Array . ConvertAll ( fields , f => f . Name ) : new string [ 0 ] ;
75
+ PropertyInfo [ ] properties = _type . GetProperties ( defaultBindingFlags ) ;
76
+ MethodInfo [ ] methods = _type . GetMethods ( defaultBindingFlags ) ;
77
+ MethodInfo [ ] fullyFledgedMethods = methods . Length > 0 ?
78
+ Array . FindAll ( methods , ReflectionHelpers . IsFullyFledgedMethod ) : methods ;
79
+
80
+ _fields = fields ;
81
+ _fieldNames = fieldNames ;
82
+ _properties = properties ;
83
+ _methods = fullyFledgedMethods ;
79
84
}
80
85
81
86
@@ -89,8 +94,7 @@ protected object InvokeStandardMember(string name, BindingFlags invokeAttr, Bind
89
94
if ( ( processedInvokeAttr . HasFlag ( BindingFlags . GetProperty )
90
95
|| processedInvokeAttr . HasFlag ( BindingFlags . SetProperty )
91
96
|| processedInvokeAttr . HasFlag ( BindingFlags . PutDispProperty ) )
92
- && ! _properties . Any ( p => p . Name == name )
93
- && _fields . Any ( p => p . Name == name ) )
97
+ && Array . IndexOf ( _fieldNames , name ) != - 1 )
94
98
{
95
99
if ( processedInvokeAttr . HasFlag ( BindingFlags . GetProperty ) )
96
100
{
@@ -125,9 +129,7 @@ Type IReflect.UnderlyingSystemType
125
129
126
130
FieldInfo IReflect . GetField ( string name , BindingFlags bindingAttr )
127
131
{
128
- FieldInfo field = _fields . SingleOrDefault ( f => f . Name == name ) ;
129
-
130
- return field ;
132
+ throw new NotImplementedException ( ) ;
131
133
}
132
134
133
135
FieldInfo [ ] IReflect . GetFields ( BindingFlags bindingAttr )
@@ -147,9 +149,7 @@ MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr)
147
149
148
150
MethodInfo IReflect . GetMethod ( string name , BindingFlags bindingAttr )
149
151
{
150
- MethodInfo method = _methods . SingleOrDefault ( m => m . Name == name ) ;
151
-
152
- return method ;
152
+ throw new NotImplementedException ( ) ;
153
153
}
154
154
155
155
MethodInfo IReflect . GetMethod ( string name , BindingFlags bindingAttr , Binder binder , Type [ ] types , ParameterModifier [ ] modifiers )
@@ -169,9 +169,7 @@ PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr)
169
169
170
170
PropertyInfo IReflect . GetProperty ( string name , BindingFlags bindingAttr )
171
171
{
172
- PropertyInfo property = _properties . SingleOrDefault ( p => p . Name == name ) ;
173
-
174
- return property ;
172
+ throw new NotImplementedException ( ) ;
175
173
}
176
174
177
175
PropertyInfo IReflect . GetProperty ( string name , BindingFlags bindingAttr , Binder binder ,
0 commit comments