Example #1
0
        public void Interface()
        {
            // Arrange
            J      value = new C();
            string name  = null;

            // Act
            TypeSwitch.On(value)
            .Case((J x) => name  = x.ShortName)
            .Case((C x) => name  = x.FullName)
            .Default((x) => name = x.ToString());

            // Assert
            Assert.AreEqual("CJ", name);
        }
Example #2
0
        public void DefaultNoArg()
        {
            // Arrange
            var    value = new object();
            string name  = null;

            // Act
            TypeSwitch.On(value)
            .Case((J x) => name = x.ShortName)
            .Case((C x) => name = x.FullName)
            .Default(() => name = "Default");

            // Assert
            Assert.AreEqual("Default", name);
        }
Example #3
0
        public void DerivedClassAsBaseClass()
        {
            // Arrange
            A      value = new C();
            string name  = null;

            // Act
            TypeSwitch.On(value)
            .Case((C x) => name  = x.FullName)
            .Case((B x) => name  = x.LongName)
            .Case <A>(() => name = "A")
            .Default((x) => name = x.ToString());

            // Assert
            Assert.AreEqual("C", name);
        }
Example #4
0
        public void BaseClassObject()
        {
            // Arrange
            object value = new A();
            string name  = null;

            // Act
            TypeSwitch.On(value)
            .Case((C x) => name  = x.FullName)
            .Case((B x) => name  = x.LongName)
            .Case <A>(() => name = "A")
            .Default((x) => name = x.ToString());

            // Assert
            Assert.AreEqual("A", name);
        }
Example #5
0
        public void InterfaceObject()
        {
            // Arrange
            object value = new C();
            string name  = null;

            // Act
            TypeSwitch.On(value)
            .Case((I x) => name  = x.GetID())
            .Case((J x) => name  = x.ShortName)
            .Case((C x) => name  = x.FullName)
            .Case <A>(() => name = "A")
            .Default((x) => name = x.ToString());

            // Assert
            Assert.AreEqual("CI", name);
        }