Пример #1
0
        public void should_be_return_type_covariance()
        {
            var demoObject = new DelegateTypeVarianceDemoClass();

            Func <object> delegateReturnsObject = demoObject.ReturnsMoreSpecificType;

            object returnedValue = delegateReturnsObject();

            // change variable value to fix test.
            object expectedValue = "Hello";

            Assert.Equal(expectedValue, returnedValue);
        }
Пример #2
0
        public void should_be_parameter_contravariance()
        {
            var demoObject = new DelegateTypeVarianceDemoClass();

            Func <object, string> delegateAcceptsObject = demoObject.InputMoreGeneralType;
            Func <string, string> delegateAcceptsString = delegateAcceptsObject;

            string returnedValue = delegateAcceptsString("Good");

            // change variable value to fix test.
            const string expectedValue = "Good";

            Assert.Equal(expectedValue, returnedValue);
        }