Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » XML » Serializing » Downloads
 

Yet Another XML Serialization Library for the .NET Framework

By , 2 Oct 2012
 
YAXLib-src-1.1.zip
YAXLib
DemoApplication
Properties
Settings.settings
SampleClasses
YAXLib
Properties
YAXLib-src-1.zip
Settings.settings
YAXLib-src-1_1.zip
Settings.settings
YAXLib-src-2.0.zip
Settings.settings
LocalTestRun.testrunconfig
YAXLib.vsmdi
YAXLibTests
Properties
Test References
// Copyright 2009 - 2010 Sina Iravanian - <sina@sinairv.com>
//
// This source file(s) may be redistributed, altered and customized
// by any means PROVIDING the authors name and all copyright
// notices remain intact.
// THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED. USE IT AT YOUR OWN RISK. THE AUTHOR ACCEPTS NO
// LIABILITY FOR ANY DATA DAMAGE/LOSS THAT THIS PRODUCT MAY CAUSE.
//-----------------------------------------------------------------------

using YAXLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Collections;

namespace YAXLibTests
{
    [TestClass()]
    public class ReflectionUtilsTest
    {
        [TestMethod]
        public void IsArrayTest()
        {
            Assert.IsTrue(ReflectionUtils.IsArray(typeof(int[])));
            Assert.IsTrue(ReflectionUtils.IsArray(typeof(int[,])));
            Assert.IsTrue(ReflectionUtils.IsArray(typeof(Array)));
            Assert.IsFalse(ReflectionUtils.IsArray(typeof(List<int>)));
            Assert.IsFalse(ReflectionUtils.IsArray(typeof(List<>)));
            Assert.IsFalse(ReflectionUtils.IsArray(typeof(Dictionary<,>)));
            Assert.IsFalse(ReflectionUtils.IsArray(typeof(Dictionary<int, string>)));
            Assert.IsFalse(ReflectionUtils.IsArray(typeof(string)));
        }
        
        [TestMethod]
        public void IsCollectionTypeTest()
        {
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(int[])));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(Array)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(List<int>)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(List<>)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(Dictionary<,>)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(Dictionary<int,string>)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(IEnumerable)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(IEnumerable<>)));
            Assert.IsTrue(ReflectionUtils.IsCollectionType(typeof(IEnumerable<int>)));
            Assert.IsFalse(ReflectionUtils.IsCollectionType(typeof(string)));
        }

        [TestMethod]
        public void GetCollectionItemTypeTest()
        {
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(IEnumerable<int>)) == typeof(int));
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(double[])) == typeof(double));
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(float[][])) == typeof(float[]));
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(string[,])) == typeof(string));
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(List<char>)) == typeof(char));
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(Dictionary<int,char>)) == typeof(KeyValuePair<int, char>));
            Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(Dictionary<Dictionary<int, double>, char>)) == typeof(KeyValuePair<Dictionary<int, double>, char>));

            //Assert.IsTrue(ReflectionUtils.GetCollectionItemType(typeof(IEnumerable<>)) == typeof(object));
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of use and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License

About the Author

Sina Iravanian
Software Developer
Australia Australia
Member
A software designer and developer

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 2 Oct 2012
Article Copyright 2009 by Sina Iravanian
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid