Example #1
0
    public static void Main (string[] args) {
        var instanceA = new CustomType();
        var instanceB = new CustomType2();

        Console.WriteLine(
            "{0} {1} {2} {3}", instanceA, instanceA.GetType(), 
            instanceB, instanceB.GetType()
        );
    }
Example #2
0
        public void ArrayCanBeOfAnyType()
        {
            CustomType[] arrayOfCustomTypes = new CustomType[] { new CustomType() };
            Assert.AreSame(____, arrayOfCustomTypes.GetType(), "Array elements can be of any type, including an array type.");

            int[] array = { 1, 2, 3 };
            ChangeSecondElementOfArrayToOne(array);
            Assert.AreEqual(____, array[1], "Array types are reference types derived from the abstract base type Array");
        }
Example #3
0
    public static void Main(string[] args)
    {
        var instanceA = new CustomType();
        var instanceB = new CustomType2();

        Console.WriteLine(
            "{0} {1} {2} {3}", instanceA, instanceA.GetType(),
            instanceB, instanceB.GetType()
            );
    }
        public void Can_Serialize_type_with_object()
        {
            var obj = new CustomType {
                CustomId = 1, CustomName = "Name"
            };
            var typeWithObject = new Tuple(obj.GetType(), obj);

            byte[] bytes = Encoding.UTF8.GetBytes(JsonSerializer.SerializeToString(typeWithObject));

            var bytesStr           = Encoding.UTF8.GetString(bytes);
            var fromTypeWithObject = JsonSerializer.DeserializeFromString <Tuple>(bytesStr);
            var newObj             = fromTypeWithObject.Value as CustomType;

            Assert.That(newObj.CustomId, Is.EqualTo(obj.CustomId));
            Assert.That(newObj.CustomName, Is.EqualTo(obj.CustomName));
        }
Example #5
0
        public void Can_Serialize_type_with_object()
        {
            var obj = new CustomType {
                CustomId = 1, CustomName = "Name"
            };
            var typeWithObject = new Tuple(obj.GetType(), obj);
            var bytes          = Encoding.UTF8.GetBytes(typeWithObject.ToJson());

            var bytesStr           = Encoding.UTF8.GetString(bytes);
            var fromTypeWithObject = bytesStr.FromJson <Tuple>();
            var newObj             = ((JObject)fromTypeWithObject.Value).ToObject <CustomType>();

            Assert.NotNull(newObj);
            Assert.That(newObj.CustomId, Is.EqualTo(obj.CustomId));
            Assert.That(newObj.CustomName, Is.EqualTo(obj.CustomName));
        }