pilotboba wrote:
Otis wrote:
You can use an overload of SetEntityFieldError() which accepts a boolean which allows you not to append but to overwrite the error message.
But, even if I pass false, the default message is still getting populated. I really only want my message(s) in there.
I think I indeed went a little overboard with these. I think by just logging overflow messages which are caught by the entity's own validation routine (which checks if a string is inside the set bounds of the field for example) are enough. In the case of such a failure, the call will never reach the validator anyway, as the value is already rejected.
BTW: There is no overload, you have to always pass the bool.
true, I didn't check the signature
Otis wrote:
Yes, at the moment you've to clear it because you also set it. Your point is however food for thought. I'm a little undecided in this though: it would be great if it was reset automatically, however on the other hand, what if someone wants to keep the errors for checks later on (not using IDataError for display purposes for example), or better: wants to control when the errors are overwritten?
Well, if you are using this for what it is designed for, the Winforms data provider. My understanding is that as soon as the user types the correct value into the field you want the erorr indicator (! thing) to go away. If you need leave the error message there, it won't.
Good point. I'll see that I can change this.
I can clear the error message, but it seems to me that this should be the default. Also, I can't remove the key from the hashtable, I can only clear the string.
I'll change it that it will remove the key when the input is null or empty.
It seems to me if someone wants to keep the error messages then THAT should be the time you need to add code, since this is the more exceptional behavior. You could possibly add an OnFieldErrorChanging() method to deal with this. However, I can already intercept the error message in my field validator code.
indeed, seems like unnecessary code to me to add.
Otis wrote:
I'm not certain what you mean by error in a property, could you give an example?
The IDataErrorInfo interface has two members:
The indexer (Item) member. And the Error member. The Error members description in help is "Gets an error message indicating what is wrong with this object."
In your implementation you are treating the errors in the Item collection seperatly from the value that the Error Method returns. But, my expectation is that Error() would return the addregate of all the messages in the Item collection. I would test this with a DataSet but I don't know how to use them in a way that a business rule would populate a value in the IDataErrorInfo member.
BOb
I don't see it as the aggregate of the field errors, that's why there's also a SetEntityError method. The (stupid) docs of IDataErrorInfo say only that it is an error message, not that it should aggregate the errors of the fields.
All in all it illustrates perfectly why this interface is silly, but people requested it, so I added it.
You made some good points and I'll make the changes. Not the last one about the Error property though.