non base class

Topics: Developer Forum
Dec 11, 2006 at 4:25 PM
Is there a way to make use of the EViL validation without having to inherit from the base class (such as some static methods perhaps) so I could make use of it without having to change (or if I'm not able to change) the base entity classes?
Coordinator
Dec 11, 2006 at 7:09 PM
That's something that is currently under consideration (and has been from the beginning actually). Inheriting from the abstract base class made sense to get EViL out the door, but I knew I'd come back to it. Stay tuned for further development on that issue.
Coordinator
Dec 18, 2006 at 5:09 AM
The next release (in the next couple days) will allow developers to use EViL without having to inherit from the EvilBaseEntity abstract class. A new class named EvilValidator has been added that allows you to do this.

For instance, you can validate an entity by doing something similar to this:

// Assuming you've decorated the Customer class with
// the appropriate validation attributes
Customer c = new Customer();
c.FirstName = "Joe";
c.LastName = "Smith";

// Create a new EvilValidator and give it the entity to validate
EvilValidator ev = new EvilValidator(c);

if (!ev.IsValid())
{
// Loop through validation errors collection
foreach (string s in ev.ValidationErrors)
{
}
}
Dec 20, 2006 at 1:17 PM
I've seen the last implementation of EvilValidator class. I don't like it because now when inheriting from EvilBaseEntity, your constructors must call the base constructor class. If you don't, the EvilValidator won't have a correct reference to validate (and you have to remember it).

I would prefer another approach to the problem: create an Interface, e.g. IEvilEntity which contains the method IsValid and the ValidationErrors collection. This would be great, because I don't have to inherit from EvilBaseEntity but I can consume the funcionality.

This would resolve another problem I've found with the EvilBaseEntity class: I have a class which inherits from EvilBaseEntity. My class is marked as Serializable, but because EvilBaseEntity is not marked as Serializable, I cannot Serialize my class.

Thanks for your attention.
I like Entity Validation Library and I've started using it.
Coordinator
Dec 20, 2006 at 2:54 PM
Let me address these in parts:

1. Your issue with the EvilValidator class.
- The EvilValidator is not meant to be used if your entities inherit from EvilBaseEntity. The EvilValidator class was created specifically for developers who either don't want to or can't inherit from EvilBaseEntity. It sounds like you're trying to use EvilValidator with entities that inherit from EvilBaseEntity, which is not advisable.

2. Creating an interface.
- This is something that's been brought up before and I've been going back and forth on the issue for awhile now. Currently, I'm not entirely sold that an interface will actually provide much value, especially with the existing abstract base class (EvilBaseEntity) and EvilValidator. However, it is something I will continue to mull over.

3. EvilBaseEntity not being Serializable.
- Damn, not sure how I missed that, but I'm fixing that now.
Dec 20, 2006 at 6:25 PM
About point 1:

Yes, I'm referring to the case where my class inherits from EvilEntityBase, but I don't use EvilValidator. What I tried to explain is that EvilEntityBase uses EvilValidator, so if I don't call the base constructor from my class constructor, the EvilEntityBase won't create the reference to the validated object. I think this is a weak design point. Example:

if I do:

public class myBase: EvilEntityBase
{
public myBase(): base(){}
}

validation works, but if do:

public class myBase: EvilEntityBase
{
public myBase() {}
}

validation won't work (and the same situation occurs with the classes that inherit from myBase.

This is one of the reasons why I think an interface will help, you only have to be sure you implement it.

Thanks for your responses.
Dec 21, 2006 at 9:14 AM
I've seen the last build and I try to Serialize. You must mark EvilValidator as Serializable as well.

Thanks.
Coordinator
Dec 21, 2006 at 11:12 AM
Woops. EvilValidator is now Serializable as well. It's in the 1.0.1.0 release.