11#if ! NETSTANDARD
22using System ;
33using System . Globalization ;
4- using System . Linq ;
54using System . Reflection ;
65
6+ using MsieJavaScriptEngine . Helpers ;
7+
78namespace MsieJavaScriptEngine
89{
910 /// <summary>
@@ -22,7 +23,7 @@ internal abstract class HostItemBase : IReflect
2223 protected readonly object _target ;
2324
2425 /// <summary>
25- /// JavaScript engine mode
26+ /// JS engine mode
2627 /// </summary>
2728 protected readonly JsEngineMode _engineMode ;
2829
@@ -31,6 +32,11 @@ internal abstract class HostItemBase : IReflect
3132 /// </summary>
3233 private readonly FieldInfo [ ] _fields ;
3334
35+ /// <summary>
36+ /// List of field names
37+ /// </summary>
38+ private string [ ] _fieldNames ;
39+
3440 /// <summary>
3541 /// List of properties
3642 /// </summary>
@@ -63,19 +69,18 @@ protected HostItemBase(Type type, object target, JsEngineMode engineMode, bool i
6369 _target = target ;
6470 _engineMode = engineMode ;
6571
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 ;
7984 }
8085
8186
@@ -89,8 +94,7 @@ protected object InvokeStandardMember(string name, BindingFlags invokeAttr, Bind
8994 if ( ( processedInvokeAttr . HasFlag ( BindingFlags . GetProperty )
9095 || processedInvokeAttr . HasFlag ( BindingFlags . SetProperty )
9196 || processedInvokeAttr . HasFlag ( BindingFlags . PutDispProperty ) )
92- && ! _properties . Any ( p => p . Name == name )
93- && _fields . Any ( p => p . Name == name ) )
97+ && Array . IndexOf ( _fieldNames , name ) != - 1 )
9498 {
9599 if ( processedInvokeAttr . HasFlag ( BindingFlags . GetProperty ) )
96100 {
@@ -125,9 +129,7 @@ Type IReflect.UnderlyingSystemType
125129
126130 FieldInfo IReflect . GetField ( string name , BindingFlags bindingAttr )
127131 {
128- FieldInfo field = _fields . SingleOrDefault ( f => f . Name == name ) ;
129-
130- return field ;
132+ throw new NotImplementedException ( ) ;
131133 }
132134
133135 FieldInfo [ ] IReflect . GetFields ( BindingFlags bindingAttr )
@@ -147,9 +149,7 @@ MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr)
147149
148150 MethodInfo IReflect . GetMethod ( string name , BindingFlags bindingAttr )
149151 {
150- MethodInfo method = _methods . SingleOrDefault ( m => m . Name == name ) ;
151-
152- return method ;
152+ throw new NotImplementedException ( ) ;
153153 }
154154
155155 MethodInfo IReflect . GetMethod ( string name , BindingFlags bindingAttr , Binder binder , Type [ ] types , ParameterModifier [ ] modifiers )
@@ -169,9 +169,7 @@ PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr)
169169
170170 PropertyInfo IReflect . GetProperty ( string name , BindingFlags bindingAttr )
171171 {
172- PropertyInfo property = _properties . SingleOrDefault ( p => p . Name == name ) ;
173-
174- return property ;
172+ throw new NotImplementedException ( ) ;
175173 }
176174
177175 PropertyInfo IReflect . GetProperty ( string name , BindingFlags bindingAttr , Binder binder ,
0 commit comments