Пример #1
0
 public ObjectInstance Construct(JsValue[] arguments)
 {
     try
     {
         var parameters = _engine.BuildArgs(_constructor, arguments);
         var obj        = _constructor.Invoke(parameters);
         return(_engine.GetDomNode(obj));
     }
     catch
     {
         throw new JavaScriptException(_engine.Jint.Error);
     }
 }
Пример #2
0
        public static void AddInstance(this EngineInstance engine, ObjectInstance obj, Type type)
        {
            var attributes = type.GetTypeInfo().GetCustomAttributes <DomInstanceAttribute>();
            var info       = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(m => m.GetParameters().Length == 0);

            if (info != null)
            {
                foreach (var attribute in attributes)
                {
                    var instance = info.Invoke(null);

                    if (instance != null)
                    {
                        var node = engine.GetDomNode(instance);
                        obj.FastSetProperty(attribute.Name, new PropertyDescriptor(node, false, true, false));
                    }
                }
            }
        }
        public static JsValue ToJsValue(this Object obj, EngineInstance engine)
        {
            if (obj == null)
                return JsValue.Null;

            if (obj is String)
                return new JsValue((String)obj);
            else if (obj is Int32)
                return new JsValue((Int32)obj);
            else if (obj is UInt32)
                return new JsValue((UInt32)obj);
            else if (obj is Double)
                return new JsValue((Double)obj);
            else if (obj is Single)
                return new JsValue((Single)obj);
            else if (obj is Boolean)
                return new JsValue((Boolean)obj);
            else if (obj is Enum)
                return new JsValue(Convert.ToInt32(obj));

            return engine.GetDomNode(obj);
        }
Пример #4
0
        public static JsValue ToJsValue(this Object obj, EngineInstance engine)
        {
            if (obj != null)
            {
                if (obj is String)
                {
                    return(new JsValue((String)obj));
                }
                else if (obj is Int32)
                {
                    return(new JsValue((Int32)obj));
                }
                else if (obj is UInt32)
                {
                    return(new JsValue((UInt32)obj));
                }
                else if (obj is Double)
                {
                    return(new JsValue((Double)obj));
                }
                else if (obj is Single)
                {
                    return(new JsValue((Single)obj));
                }
                else if (obj is Boolean)
                {
                    return(new JsValue((Boolean)obj));
                }
                else if (obj is Enum)
                {
                    return(new JsValue(Convert.ToInt32(obj)));
                }

                return(engine.GetDomNode(obj));
            }

            return(JsValue.Null);
        }