public void ObjectSetterValuePerfTest()
        {
            SimpleObject o = new SimpleObject();
            PropertyInfo property = o.GetType().GetProperty("IntValue");
            MethodInfo method = property.GetSetMethod();
            int iterations = 1000;
            Stopwatch sw = new Stopwatch();
            sw.Start();
            for (int i = 0; i < iterations; i++)
            {
                method.Invoke(o, new object[] { 32 });
            }
            sw.Stop();
            Debug.WriteLine("Refelection Test: " + sw.ElapsedMilliseconds);

            sw.Reset();
            sw.Start();
            DynamicMethodUtil.GenericSetter setter = DynamicMethodUtil.CreatePropertySetter(property);
            for (int i = 0; i < iterations; i++)
            {
                setter(o, 32);
            }
            sw.Stop();
            Debug.WriteLine("Refelection Test: " + sw.ElapsedMilliseconds);

        }
 public void ObjectSetterReferenceTest()
 {
     SimpleObject o = new SimpleObject();
     PropertyInfo property = o.GetType().GetProperty("StringValue");
     DynamicMethodUtil.GenericSetter setter = DynamicMethodUtil.CreatePropertySetter(property);
     setter(o, "TestValue");
     Assert.AreEqual("TestValue", o.StringValue, "String Property Not Set");
 }
 public void ObjectSetterValueTest()
 {
     SimpleObject o = new SimpleObject();
     PropertyInfo property = o.GetType().GetProperty("IntValue");
     DynamicMethodUtil.GenericSetter setter = DynamicMethodUtil.CreatePropertySetter(property);
     setter(o, 32);
     Assert.AreEqual(32, o.IntValue, "Int Property Not Set");
 }
Ejemplo n.º 4
0
        public void WhenHasPublicObjectField_ObjectIsSerialized()
        {
            MockFields src = new MockFields();
            SimpleObject so = new SimpleObject();
            so.IntValue = 23;
            src.SimpleObj = so;
            Serializer s = new Serializer(typeof(MockFields));
            string result = s.Serialize(src);
            MockFields dest = (MockFields)s.Deserialize(result);
            Assert.AreEqual(23, dest.SimpleObj.IntValue);

        }
        public void SimpleObjectLinkedList()
        {
            Serializer s = new Serializer(typeof(LinkedList<SimpleObject>));
            LinkedList<SimpleObject> objects = new LinkedList<SimpleObject>();
            SimpleObject obj = null;
            
            // object 1
            obj = new SimpleObject();
            obj.BoolValue = true;
            obj.ByteValue = 0xf1;
            obj.CharValue = 'a';
            obj.DoubleValue = double.MinValue;
            obj.FloatValue = float.MinValue;
            obj.IntValue = 32;
            obj.LongValue = 39000;
            obj.ShortValue = 255;
            obj.StringValue = "AA";

            objects.AddLast(obj);

            // object 2
            obj = new SimpleObject();
            obj.BoolValue = false;
            obj.ByteValue = 0xf2;
            obj.CharValue = 'b';
            obj.DoubleValue = double.MaxValue;
            obj.FloatValue = float.MaxValue;
            obj.IntValue = 33;
            obj.LongValue = 39001;
            obj.ShortValue = 256;
            obj.StringValue = "BB";

            objects.AddLast(obj);

            string result = s.Serialize(objects);

            LinkedList<SimpleObject> actual = (LinkedList<SimpleObject>)s.Deserialize(result);

            CollectionAssert.AreEqual(objects, actual);
        }
Ejemplo n.º 6
0
 public override bool Equals(object obj)
 {
     if (base.Equals(obj))
     {
         return(true);
     }
     else if (obj != null && obj.GetType() == typeof(SimpleObject))
     {
         SimpleObject other = (SimpleObject)obj;
         return(other._boolValue == this._boolValue &&
                other._byteValue == this._byteValue &&
                other._charValue == this._charValue &&
                other._doubleValue == this._doubleValue &&
                other._floatValue == this._floatValue &&
                other._intValue == this._intValue &&
                other._longValue == this._longValue &&
                other._shortValue == this._shortValue &&
                other._stringValue == this._stringValue);
     }
     else
     {
         return(false);
     }
 }
        public void DictionaryToListTest()
        {
            Serializer s = new Serializer(typeof(Dictionary<string, SimpleObject>));
            DictionaryToListConverter converter = new DictionaryToListConverter();
            converter.Context = "StringValue";
            s.Config.RegisterTypeConverter(typeof(Dictionary<string, SimpleObject>), converter);
            Dictionary<string, SimpleObject> dictionary = new Dictionary<string, SimpleObject>();
            dictionary["One"] = new SimpleObject();
            dictionary["One"].StringValue = "One";
            dictionary["One"].IntValue = 1;

            dictionary["Two"] = new SimpleObject();
            dictionary["Two"].StringValue = "Two";
            dictionary["Two"].IntValue = 2;

            object list = converter.ConvertFrom(dictionary, s.Context);
            Assert.IsTrue(s.Config.TypeHandlerFactory[list.GetType()].IsCollection(), "Converted list is not a collection");

            Dictionary<string, SimpleObject> targetDictionary = (Dictionary<string, SimpleObject>) converter.ConvertTo(list, dictionary.GetType(), s.Context);
            Assert.AreEqual(2, targetDictionary.Count, "Wrong number of items");
            Assert.IsTrue(targetDictionary.ContainsKey("One"), "Key (One) not in converted dictionary");
            Assert.IsTrue(targetDictionary.ContainsKey("Two"), "Key (Two) not in converted dictionary");

            Assert.AreEqual(1, targetDictionary["One"].IntValue, "One Value wrong");
            Assert.AreEqual(2, targetDictionary["Two"].IntValue, "Two Value wrong");
        }