-
-
Notifications
You must be signed in to change notification settings - Fork 534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataGrid "Cannot create an abstract class" when UseValidation=true #3318
Comments
Hello, So the problem is that when you go into edit mode, internally we have to create a dummy object based on your class for validation purposes. Since you've provided an interface it does not know how to instantiate it, therefore throws the error So my guess is that we can ignore interfaces as that can be virtually anything and we can't know how to provide an instance for it, it should also have no negative effect on the DataGrid's validation I believe, right @stsrki ? Edit:
You are also right, that if |
Can we also do something similar to what we have for the new item? We have |
Seems like an idea. So fix IsListOrCollection on 0.9.5 which should fix the OP's issue. |
Describe the bug
If I try to add or edit a row with a specific type (contains an
ICollection<>
-Property), I get the above error message. The stack trace isTo Reproduce
Here's an example
New
orEdit
on any entry and see the errorValues
is already set (use of property initializer orNum = 3
) no editing is availableb) If you use
List<>
instead ofIList<>
it works.Expected behavior
Ideally, there's no difference between
List<>
andIList<>
-properties.Since that will mean that you have to guess what implementation of an interface one will have to use, I think at least the property should be empty (and initializers should not be overwritten).
So in that cases empty (without error message) would/should be fine.
Additional context
While investigating, I've tested
IsListOrCollection
, too (don't know if that's part of the problem/soluton). And that behaves a bit strange to me (but I'm unsure)The current code is
Blazorise/Source/Extensions/Blazorise.DataGrid/ExtensionMethods.cs
Lines 53 to 56 in 8990c56
Since
IList
inheritsICollection
, the first line is superflous. But the striking part is the last line. I've never seen open generics used in that way and I think (and have tested) that this returns (nearly) always false.If you want to detect all enumerables, just use
typeof(IEnumerable).IsAssignableFrom(type)
(IEnumerable<>
inheritsIEnumerable
). But by doing so, you will have all the collection types returning true, thus e.g.typeof(string)
(as it's a collection ofchar
), too.. Don't know if that's the desired behavior.From the name
IsListOrCollection
I assume you want to detect collections only, so this might be a solution(should be renamed to
IsCollection
..)The text was updated successfully, but these errors were encountered: