Example #1
0
        public void EnumerateProperties_JObject()
        {
            GameThread.IgnoreThreadRestrictions = true;
            using (var ge = new GameEngine(null))
            {
                ge.EngineInitialized.WaitOne();
                var objs = new List <object>();

                var adders = new
                {
                    a = 12,
                    b = 14,
                    c = new
                    {
                        d = 15
                    }
                };

                var obj = JObject.FromObject(adders);

                var props = ObjectDiff.EnumerateProperties(obj).ToDictionary(x => x.Name, x => x.Value);

                Assert.AreEqual(12, ((JValue)props["a"]).Value);
                Assert.AreEqual(14, ((JValue)props["b"]).Value);
            }
        }
Example #2
0
        public void EnumerateProperties()
        {
            GameThread.IgnoreThreadRestrictions = true;
            using (var ge = new GameEngine(null))
            {
                ge.EngineInitialized.WaitOne();
                var objs = new List <object>();

                var adders = new
                {
                    a = 12,
                    b = 14,
                    c = new
                    {
                        d = 15
                    }
                };
                var adderProps = adders.GetType().GetProperties();
                IDictionary <string, object> adderPropsDick = adderProps.ToDictionary(x => x.Name, x => x.GetValue(adders));
                {
                    dynamic obj = new ExpandoObject();
                    foreach (var prop in adderPropsDick)
                    {
                        (obj as IDictionary <string, object>).Add(prop.Key, prop.Value);
                    }
                    objs.Add(obj);
                }

                {
                    StateClass obj = new StateClass(ge);

                    foreach (var prop in adderPropsDick)
                    {
                        Dynamic.InvokeSet(obj, prop.Key, prop.Value);
                    }

                    objs.Add(obj);
                }

                {
                    objs.Add(adders);
                    objs.Add(adderPropsDick);
                    objs.Add(adderPropsDick.AsEnumerable());
                }

                foreach (var obj in objs)
                {
                    var objProps = ObjectDiff.EnumerateProperties(obj)
                                   .Where(x => x.Name != "users")
                                   .ToArray();
                    foreach (var prop in objProps)
                    {
                        Assert.Contains(prop.Name, adderPropsDick.Keys.ToArray());
                        Assert.AreEqual(prop.Value, adderPropsDick[prop.Name]);
                    }
                    foreach (var prop in adderPropsDick)
                    {
                        Assert.Contains(prop.Key, objProps.Select(x => x.Name).ToArray());
                        Assert.AreEqual(prop.Value, objProps.First(x => x.Name == prop.Key).Value);
                    }
                }
            }
        }