public void TestCanCastSimple() { Assert.True(ReflectionUtil.CanCast(typeof(float), 4)); Assert.True(ReflectionUtil.CanCast(typeof(float), 3.3f)); Assert.True(ReflectionUtil.CanCast(typeof(float), 5.5)); Assert.True(ReflectionUtil.CanCast(typeof(double), 6f)); Assert.False(ReflectionUtil.CanCast(typeof(string), 3.3f)); Assert.True(ReflectionUtil.CanCast(typeof(Simple), new Simple())); Assert.True(ReflectionUtil.CanCast(typeof(Simple), 3)); Assert.False(ReflectionUtil.CanCast(typeof(System.Text.ASCIIEncoding), new Simple())); Assert.True(ReflectionUtil.CanCast(typeof(System.DateTime), System.DateTime.Now)); Assert.False(ReflectionUtil.CanCast(typeof(int), "3")); }
public void TestCanCastInheritance() { Assert.True(ReflectionUtil.CanCast(typeof(ClassWithInterface), new ChildClass())); Assert.True(ReflectionUtil.CanCast(typeof(ClassWithInterface), new GroundChildClass())); Assert.False(ReflectionUtil.CanCast(typeof(ChildClass), new ClassWithInterface())); }
public void TestCanCastGeneric() { Assert.False(ReflectionUtil.CanCast(typeof(GenericOne <>), new GenericOne <int> ())); Assert.True(ReflectionUtil.CanCast(typeof(GenericOne <int>), new GenericOne <int> ())); Assert.False(ReflectionUtil.CanCast(typeof(GenericOne <int>), new GenericOne <string> ())); }
public void TestCanCastInterface() { Assert.True(ReflectionUtil.CanCast(typeof(ITest), new ClassWithInterface())); Assert.True(ReflectionUtil.CanCast(typeof(ITest), new ChildClass())); }