I have an Email
object and am attempting to validate the number of attachments that are in its List<Attachment>
property.
The trick is that we consume the Send()
method across a WCF service. It's easy to validate it server side, but I want to validate it client side first.
I have generated a library that others are supposed to use in order to consume the service, which in turn has a proxy containing all the objects and available methods. I think I should be able to overload the Add()
method on the GenericList with some custom code so the collection is checked when anything is added, and if it exceeds the specified maximum then an exception is thrown.
public partial class List<Attachment>
{
public void Add(Attachment item)
{
base.Add(item);
if (this.Count() > maxAttachments)
{
throw new Exception("fail")
}
}
}
This doesn't work - I can't class base.Add() and I can't define partial class with a specified type.
How do I create an overload for the Add method so that I can include some custom code?