|
@@ -4,19 +4,20 @@ using System.Reflection;
|
|
using Jint.Native;
|
|
using Jint.Native;
|
|
using Jint.Native.Object;
|
|
using Jint.Native.Object;
|
|
using Jint.Runtime.Descriptors;
|
|
using Jint.Runtime.Descriptors;
|
|
-using Jint.Runtime.Descriptors.Specialized;
|
|
|
|
|
|
+using Jint.Runtime.Descriptors.Specialized;
|
|
using System.Collections;
|
|
using System.Collections;
|
|
|
|
|
|
namespace Jint.Runtime.Interop
|
|
namespace Jint.Runtime.Interop
|
|
{
|
|
{
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Wrapps a CLR instance
|
|
|
|
|
|
+ /// Wraps a CLR instance
|
|
/// </summary>
|
|
/// </summary>
|
|
public sealed class ObjectWrapper : ObjectInstance, IObjectWrapper
|
|
public sealed class ObjectWrapper : ObjectInstance, IObjectWrapper
|
|
{
|
|
{
|
|
public Object Target { get; set; }
|
|
public Object Target { get; set; }
|
|
|
|
|
|
- public ObjectWrapper(Engine engine, Object obj): base(engine)
|
|
|
|
|
|
+ public ObjectWrapper(Engine engine, Object obj)
|
|
|
|
+ : base(engine)
|
|
{
|
|
{
|
|
Target = obj;
|
|
Target = obj;
|
|
}
|
|
}
|
|
@@ -54,9 +55,7 @@ namespace Jint.Runtime.Interop
|
|
{
|
|
{
|
|
PropertyDescriptor x;
|
|
PropertyDescriptor x;
|
|
if (Properties.TryGetValue(propertyName, out x))
|
|
if (Properties.TryGetValue(propertyName, out x))
|
|
- {
|
|
|
|
return x;
|
|
return x;
|
|
- }
|
|
|
|
|
|
|
|
var type = Target.GetType();
|
|
var type = Target.GetType();
|
|
|
|
|
|
@@ -87,51 +86,55 @@ namespace Jint.Runtime.Interop
|
|
|
|
|
|
if (methods.Any())
|
|
if (methods.Any())
|
|
{
|
|
{
|
|
- return new PropertyDescriptor(new MethodInfoFunctionInstance(Engine, methods), false, true, false);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // if no methods are found check if target implemented indexing
|
|
|
|
- if (type.GetProperties().Where(p => p.GetIndexParameters().Length != 0).FirstOrDefault() != null)
|
|
|
|
- {
|
|
|
|
- return new IndexDescriptor(Engine, propertyName, Target);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var interfaces = type.GetInterfaces();
|
|
|
|
-
|
|
|
|
- // try to find a single explicit property implementation
|
|
|
|
- var explicitProperties = (from iface in interfaces
|
|
|
|
- from iprop in iface.GetProperties()
|
|
|
|
- where propertyName.Equals(iprop.Name)
|
|
|
|
- select iprop).ToList();
|
|
|
|
-
|
|
|
|
- if (explicitProperties.Count == 1)
|
|
|
|
- {
|
|
|
|
- var descriptor = new PropertyInfoDescriptor(Engine, explicitProperties[0], Target);
|
|
|
|
- Properties.Add(propertyName, descriptor);
|
|
|
|
- return descriptor;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // try to find explicit method implementations
|
|
|
|
- var explicitMethods = (from iface in interfaces
|
|
|
|
- from imethod in iface.GetMethods()
|
|
|
|
- where propertyName.Equals(imethod.Name)
|
|
|
|
- select imethod).ToList();
|
|
|
|
-
|
|
|
|
- if (explicitMethods.Count > 0)
|
|
|
|
- {
|
|
|
|
- return new PropertyDescriptor(new MethodInfoFunctionInstance(Engine, explicitMethods.ToArray()), false, true, false);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // try to find explicit indexer implementations
|
|
|
|
- var explicitIndexers =
|
|
|
|
- (from iface in interfaces
|
|
|
|
- from iprop in iface.GetProperties()
|
|
|
|
- where iprop.GetIndexParameters().Length != 0
|
|
|
|
- select iprop).ToList();
|
|
|
|
-
|
|
|
|
- if (explicitIndexers.Count == 1)
|
|
|
|
- {
|
|
|
|
- return new IndexDescriptor(Engine, explicitIndexers[0].DeclaringType, propertyName, Target);
|
|
|
|
|
|
+ var descriptor = new PropertyDescriptor(new MethodInfoFunctionInstance(Engine, methods), false, true, false);
|
|
|
|
+ Properties.Add(propertyName, descriptor);
|
|
|
|
+ return descriptor;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // if no methods are found check if target implemented indexing
|
|
|
|
+ if (type.GetProperties().Where(p => p.GetIndexParameters().Length != 0).FirstOrDefault() != null)
|
|
|
|
+ {
|
|
|
|
+ return new IndexDescriptor(Engine, propertyName, Target);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var interfaces = type.GetInterfaces();
|
|
|
|
+
|
|
|
|
+ // try to find a single explicit property implementation
|
|
|
|
+ var explicitProperties = (from iface in interfaces
|
|
|
|
+ from iprop in iface.GetProperties()
|
|
|
|
+ where propertyName.Equals(iprop.Name)
|
|
|
|
+ select iprop).ToArray();
|
|
|
|
+
|
|
|
|
+ if (explicitProperties.Length == 1)
|
|
|
|
+ {
|
|
|
|
+ var descriptor = new PropertyInfoDescriptor(Engine, explicitProperties[0], Target);
|
|
|
|
+ Properties.Add(propertyName, descriptor);
|
|
|
|
+ return descriptor;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // try to find explicit method implementations
|
|
|
|
+ var explicitMethods = (from iface in interfaces
|
|
|
|
+ from imethod in iface.GetMethods()
|
|
|
|
+ where propertyName.Equals(imethod.Name)
|
|
|
|
+ select imethod).ToArray();
|
|
|
|
+
|
|
|
|
+ if (explicitMethods.Length > 0)
|
|
|
|
+ {
|
|
|
|
+ var descriptor = new PropertyDescriptor(new MethodInfoFunctionInstance(Engine, explicitMethods), false, true, false);
|
|
|
|
+ Properties.Add(propertyName, descriptor);
|
|
|
|
+ return descriptor;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // try to find explicit indexer implementations
|
|
|
|
+ var explicitIndexers =
|
|
|
|
+ (from iface in interfaces
|
|
|
|
+ from iprop in iface.GetProperties()
|
|
|
|
+ where iprop.GetIndexParameters().Length != 0
|
|
|
|
+ select iprop).ToArray();
|
|
|
|
+
|
|
|
|
+ if (explicitIndexers.Length == 1)
|
|
|
|
+ {
|
|
|
|
+ return new IndexDescriptor(Engine, explicitIndexers[0].DeclaringType, propertyName, Target);
|
|
}
|
|
}
|
|
|
|
|
|
return PropertyDescriptor.Undefined;
|
|
return PropertyDescriptor.Undefined;
|