示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }