private void MappNested(JsGenericObject gres, object parentObject, IList <PropertyInfo> properties)
        {
            if (parentObject == null)
            {
                return;
            }

            foreach (var propertyInfo in properties)
            {
                var    propertyName = propertyInfo.Name;
                object childvalue;
                try
                {
                    childvalue = propertyInfo.GetValue(parentObject, null);
                }
                catch (TargetInvocationException e)
                {
                    _Logger.Info(() => $"Unable to convert property {propertyName} from {parentObject} of type {parentObject.GetType().FullName} exception {e.InnerException}");
                    continue;
                }

                var childres = Map(childvalue);
                gres.AddGlueProperty(propertyName, childres);
            }
        }
Exemplo n.º 2
0
        private void MappNested(object from, JsGenericObject gres)
        {
            if (from == null)
            {
                return;
            }

            var propertyInfos = from.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead);

            foreach (var propertyInfo in propertyInfos)
            {
                var    propertyName = propertyInfo.Name;
                object childvalue;
                try
                {
                    childvalue = propertyInfo.GetValue(from, null);
                }
                catch (Exception e)
                {
                    _Logger.Info(() => $"Unable to convert property {propertyName} from {@from} exception {e}");
                    continue;
                }

                var childres = InternalMap(childvalue);
                gres.UpdateCSharpProperty(propertyName, childres);
            }
        }
Exemplo n.º 3
0
        private void MappNested(JsGenericObject gres, IReadOnlyCollection <Tuple <PropertyInfo, object> > properties)
        {
            foreach (var property in properties)
            {
                var    propertyInfo = property.Item1;
                var    propertyName = propertyInfo.Name;
                var    parentObject = property.Item2;
                object childvalue;
                try
                {
                    childvalue = propertyInfo.GetValue(parentObject, null);
                }
                catch (TargetInvocationException e)
                {
                    _Logger.Info(() => $"Unable to convert property {propertyName} from {parentObject} of type {parentObject.GetType().FullName} exception {e.InnerException}");
                    continue;
                }

                var childres = Map(childvalue);
                gres.UpdateCSharpProperty(propertyName, childres);
            }
        }
Exemplo n.º 4
0
        public IJSCSGlue Map(object from, object additional = null)
        {
            if (from == null)
            {
                return(new JSBasicObject(null));
            }

            var res = _Cacher.GetCached(from);

            if (res != null)
            {
                return(res);
            }

            var command = from as ICommand;

            if (command != null)
            {
                return(_CommandFactory.Build(command));
            }

            var simpleCommand = from as ISimpleCommand;

            if (simpleCommand != null)
            {
                return(_CommandFactory.Build(simpleCommand));
            }

            var resultCommand = from as IResultCommand;

            if (resultCommand != null)
            {
                return(_CommandFactory.Build(resultCommand));
            }

            var type = from.GetType();

            if (_Context.IsTypeBasic(type))
            {
                return(new JSBasicObject(from));
            }

            if (type.IsEnum)
            {
                var trueres = new JSBasicObject(from);
                _Cacher.Cache(from, trueres);
                return(trueres);
            }

            var ienfro = from as IEnumerable;

            if (ienfro != null)
            {
                return(Convert(ienfro));
            }

            var propertyInfos = GetPropertyInfos(from).Concat(GetPropertyInfos(additional)).ToList();

            var gres = new JsGenericObject(from, propertyInfos.Count);

            _Cacher.Cache(from, gres);

            MappNested(gres, propertyInfos);
            return(gres);
        }
Exemplo n.º 5
0
        public IJSCSGlue InternalMap(object from, object iadditional = null)
        {
            if (from == null)
            {
                return(new JsGenericObject(_Context, null));
            }

            var res = _Cacher.GetCached(from);

            if (res != null)
            {
                return(res);
            }

            var command = from as ICommand;

            if (command != null)
            {
                return(_CommandFactory.Build(command));
            }

            var simpleCommand = from as ISimpleCommand;

            if (simpleCommand != null)
            {
                return(_CommandFactory.Build(simpleCommand));
            }

            var resultCommand = from as IResultCommand;

            if (resultCommand != null)
            {
                return(_CommandFactory.Build(resultCommand));
            }

            var type = from.GetType();

            if (_Context.WebView.Factory.IsTypeBasic(type))
            {
                return(new JSBasicObject(from));
            }

            if (type.IsEnum)
            {
                var trueres = new JSBasicObject(from);
                _Cacher.Cache(from, trueres);
                return(trueres);
            }

            var ienfro = from as IEnumerable;

            if (ienfro != null)
            {
                return(Convert(ienfro));
            }

            var gres = new JsGenericObject(_Context, from);

            _Cacher.Cache(from, gres);

            MappNested(from, gres);
            MappNested(iadditional, gres);

            return(gres);
        }
Exemplo n.º 6
0
        public IJSCSGlue UnsafelMap(object from, object iadditional = null)
        {
            if (from == null)
            {
                return(JsGenericObject.CreateNull(_Context));
            }

            var res = _Cacher.GetCached(from);

            if (res != null)
            {
                return(res);
            }

            var command = from as ICommand;

            if (command != null)
            {
                return(_CommandFactory.Build(command));
            }

            var simpleCommand = from as ISimpleCommand;

            if (simpleCommand != null)
            {
                return(_CommandFactory.Build(simpleCommand));
            }

            var resultCommand = from as IResultCommand;

            if (resultCommand != null)
            {
                return(_CommandFactory.Build(resultCommand));
            }

            IJavascriptObject value;

            if (_Context.WebView.Factory.CreateBasic(from, out value))
            {
                return(new JSBasicObject(value, from));
            }

            if (from.GetType().IsEnum)
            {
                var trueres = new JSBasicObject(_Context.WebView.Factory.CreateEnum((Enum)from), from);
                _Cacher.CacheLocal(from, trueres);
                return(trueres);
            }

            var ienfro = from as IEnumerable;

            if (ienfro != null)
            {
                return(Convert(ienfro));
            }

            var resobject = _Context.WebView.Factory.CreateObject(true);

            var gres = new JsGenericObject(_Context, resobject, from);

            _Cacher.Cache(from, gres);

            MappNested(from, resobject, gres);
            MappNested(iadditional, resobject, gres);

            return(gres);
        }