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 = ""; Assert.Equal(expectedValue, returnedValue); }
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 = null; Assert.Equal(expectedValue, returnedValue); }