Example #1
0
 public JsClr(IJintVisitor visitor, object clr)
     : this(visitor)
 {
     value = clr;
     if (value != null)
     {
         if (value is System.Collections.IEnumerable)
             clrCountProperty = propertyGetter.GetValue(value, "Count");
         else
         {
             //properties = new List<string>();
             foreach (PropertyInfo pi in value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
             {
                 DefineOwnProperty(pi.Name, new ClrPropertyDescriptor(propertyGetter, global, this, pi.Name));
             }
             foreach (FieldInfo pi in value.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
             {
                 DefineOwnProperty(pi.Name, new ClrFieldDescriptor(fieldGetter, global, this, pi.Name));
             }
             ClrMethodDescriptor cmd = null;
             foreach (MethodInfo mi in value.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
             {
                 if (cmd == null || cmd.Name != mi.Name)
                     DefineOwnProperty(mi.Name, cmd = new ClrMethodDescriptor(this, mi.Name));
             }
         }
     }
 }
 public JsClr(IJintVisitor visitor, object clr)
     : this(visitor)
 {
     value = clr;
     if (value != null)
     {
         if (value is System.Collections.IEnumerable)
         {
             clrCountProperty = propertyGetter.GetValue(value, "Count");
         }
         else
         {
             //properties = new List<string>();
             foreach (PropertyInfo pi in value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
             {
                 DefineOwnProperty(pi.Name, new ClrPropertyDescriptor(propertyGetter, global, this, pi.Name));
             }
             foreach (FieldInfo pi in value.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
             {
                 DefineOwnProperty(pi.Name, new ClrFieldDescriptor(fieldGetter, global, this, pi.Name));
             }
             ClrMethodDescriptor cmd = null;
             foreach (MethodInfo mi in value.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
             {
                 if (cmd == null || cmd.Name != mi.Name)
                 {
                     DefineOwnProperty(mi.Name, cmd = new ClrMethodDescriptor(this, mi.Name));
                 }
             }
         }
     }
 }
Example #3
0
        public JsClr(IJintVisitor visitor, object clr)
            : this(visitor)
        {
            value = clr;
            if (value != null)
            {
                //TODO: Когда нибудь, когда солнце и земля объединятся, этот костыль должен быть исправлен. Но поныне нужно помнить: namespace BitMobile.Controls только для контролов, и контролы только для него.
                // Основное назначение: из за того что UIVewItem реализует IEnumerable, мы получаем такой гемор.
                if (value is System.Collections.IEnumerable && clr.GetType().Namespace != "BitMobile.Controls")
                    clrCountProperty = _propertyGetter.GetValue(value, "Count");
                else
                {
                    //properties = new List<string>();
                    foreach (PropertyInfo pi in value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        DefineOwnProperty(pi.Name, new ClrPropertyDescriptor(_propertyGetter, _global, this, pi.Name));
                    }
                    foreach (FieldInfo pi in value.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
                    {
                        DefineOwnProperty(pi.Name, new ClrFieldDescriptor(_fieldGetter, _global, this, pi.Name));
                    }
                    ClrMethodDescriptor cmd = null;
                    foreach (MethodInfo mi in value.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
                    {
                        if (cmd == null || cmd.Name != mi.Name)
                            DefineOwnProperty(mi.Name, cmd = new ClrMethodDescriptor(this, mi.Name));
                    }

                    var entity = value as IEntity;
                    if (entity != null)
                        foreach (string column in entity.EntityType.GetColumns())
                            DefineOwnProperty(column, new ClrEntityDescriptor(_entityAccessor, _global, this, column));
                }
            }
        }
Example #4
0
        public JsClr(IJintVisitor visitor, object clr)
            : this(visitor)
        {
            value = clr;
            if (value != null)
            {
                //TODO: Когда нибудь, когда солнце и земля объединятся, этот костыль должен быть исправлен. Но поныне нужно помнить: namespace BitMobile.Controls только для контролов, и контролы только для него.
                // Основное назначение: из за того что UIVewItem реализует IEnumerable, мы получаем такой гемор.
                if (value is System.Collections.IEnumerable && clr.GetType().GetInterfaces().Contains(typeof(ILayoutable)))
                {
                    clrCountProperty = _propertyGetter.GetValue(value, "Count");
                }
                else
                {
                    //properties = new List<string>();
                    foreach (PropertyInfo pi in value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (pi.GetCustomAttributes <InjectionAttribute>().Any())
                        {
                            pi.SetValue(value, visitor.JintEngine);
                        }
                        else
                        {
                            DefineOwnProperty(pi.Name, new ClrPropertyDescriptor(_propertyGetter, _global, this, pi.Name));
                        }
                    }
                    foreach (FieldInfo pi in value.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
                    {
                        DefineOwnProperty(pi.Name, new ClrFieldDescriptor(_fieldGetter, _global, this, pi.Name));
                    }
                    ClrMethodDescriptor cmd = null;
                    foreach (MethodInfo mi in value.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
                    {
                        if (cmd == null || cmd.Name != mi.Name)
                        {
                            DefineOwnProperty(mi.Name, cmd = new ClrMethodDescriptor(this, mi.Name));
                        }
                    }

                    var entity = value as IEntity;
                    if (entity != null)
                    {
                        foreach (string column in entity.EntityType.GetColumns())
                        {
                            DefineOwnProperty(column, new ClrEntityDescriptor(_entityAccessor, _global, this, column));
                        }
                    }
                }
            }
        }