Skip to content

Commit e7cc830

Browse files
ConvertClientValue - use IsAssignableFrom (#452)
1 parent b7cb96a commit e7cc830

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

net/DevExtreme.AspNet.Data.Tests/UtilsTests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,37 @@ public void GetPrimaryKey_MultiKey() {
7474

7575
[Fact]
7676
public void ConvertClientValue_TrivialConversion() {
77-
var value = typeof(UtilsTests);
77+
object value = typeof(UtilsTests);
7878
Assert.Same(value, Utils.ConvertClientValue(value, value.GetType()));
7979
}
8080

81+
[Fact]
82+
public void ConvertClientValue_ToBaseType() {
83+
object value = typeof(int);
84+
Assert.Same(value, Utils.ConvertClientValue(value, typeof(Type)));
85+
}
86+
87+
[Fact]
88+
public void ConvertClientValue_ToImplementedInterface() {
89+
object value = 123;
90+
Assert.Same(value, Utils.ConvertClientValue(value, typeof(IConvertible)));
91+
}
92+
93+
[Fact]
94+
public void ConvertClientValue_ToSameNullable() {
95+
object value = 123;
96+
Assert.Same(value, Utils.ConvertClientValue(value, typeof(int?)));
97+
}
98+
99+
[Fact]
100+
public void ConvertClientValue_Numeric() {
101+
// https://stackoverflow.com/q/30080763 - notes about IsAssignableFrom
102+
object input = 123;
103+
object output = Utils.ConvertClientValue(input, typeof(long));
104+
Assert.NotSame(input, output);
105+
Assert.Equal(123L, output);
106+
}
107+
81108
}
82109

83110
}

net/DevExtreme.AspNet.Data/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static object ConvertClientValue(object value, Type type) {
3636
if(value == null || type == null)
3737
return value;
3838

39-
if(value.GetType() == type)
39+
if(type.IsAssignableFrom(value.GetType()))
4040
return value;
4141

4242
type = StripNullableType(type);

0 commit comments

Comments
 (0)