示例#1
0
        public void Test_GetEnumerableElementAt()
        {
            var array1 = new[] { "i1", "i2", "i3" };

            Assert.AreEqual("i1", ReflectionMethods.GetItem(array1, 0));
            Assert.AreEqual("i2", ReflectionMethods.GetItem(array1, 1));

            var al1 = new ArrayList(2)
            {
                5, "test2"
            };

            Assert.AreEqual(5, ReflectionMethods.GetItem(al1, 0));
            Assert.AreEqual("test2", ReflectionMethods.GetItem(al1, 1));

            var dict1 = new Dictionary <string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            };

            Assert.IsNotNull(ReflectionMethods.GetItem(dict1, 0));

            var list1 = new List <string> {
                "list1", "list2"
            };

            Assert.AreEqual("list1", ReflectionMethods.GetItem(list1, 0));
            Assert.AreEqual("list2", ReflectionMethods.GetItem(list1, 1));
        }
示例#2
0
        protected override void OnExecute(UIMessageContext ctx)
        {
            if (ctx.Request == null)
            {
                return;
            }

            var req = ctx.Get <GetObjectRequest>();

            if (req == null)
            {
                return;
            }

            var props = GetUIProperties(req.WidgetId, true, req.Path);

            if (!props.Any())
            {
                return;
            }

            var prop = props[0];

            if (prop.UIType.Descriptor.HasFlag(UIPropertyDescriptors.Enumerable))
            {
                if (prop.UIType.Descriptor.HasFlag(UIPropertyDescriptors.Enumerable))
                {
                    // grab index value; if null, return without creating an ObjectResponse.
                    var index = ReflectionMethods.GetIndexerValue(req.Path[0]);
                    if (index == null)
                    {
                        return;
                    }

                    var item = ReflectionMethods.GetItem(prop.Value, index.Value);
                    prop.Value = GetUIProperties(item);
                }
            }

            prop.Path = req.Path?.Union(prop.Path)?.ToArray();
            var cantCast = SetPath(prop.Value, req.Path);

            ctx.SetResponse <ObjectResponse>(res =>
            {
                res.UnknownCondition = cantCast;
                res.Property         = prop;
                res.WidgetId         = req.WidgetId;
                res.ObjectName       = UIProperty.GetLastPath(req.Path);
            });
        }