Validation of generic parameters

Topics: Validation Application Block
Aug 24, 2007 at 10:24 PM
It seems that the Validation process will not validate a generic parameter for the wcf integration. If a method is defined as:

void Update<T>(T customer);

no validation will take place. If the method is defined as:

void Update<T>(T customer)
where T : Customer;

and there is validation settings on Customer, then validation would take place for the Customer properties, but not for any additional properties of a derived class of Customer.

Perhaps the Validation app block can do such validation, and I'm just missing an attribute or something. If anyone can confirm one way or another, that would be appreciative. If not, I believe I would have to alter the wcf integration to make the call:


and then possibly extend further for arrays of type T. Thanks in advance.
Aug 28, 2007 at 2:59 PM

Validation works with the static type of the generic type parameter T, not the actual runtime type of the parameter customer. However, that wouldn't explain why it doesn't validate when you don't specify a type constraint.

In any case, AFAIK you cannot have generic parameters on methods implementing WCF service contracts. Can you describe your scenario with more detail?

Aug 28, 2007 at 4:05 PM
You are correct in regards to generic parameters on service contract methods of WCF. I was actually taking the same concept of the wcf integration and utilizing it on a message sink for a MarshalByRefObject message proxy. A couple of days later I realized this is not an issue with the integration piece given, just my implementation of a similar process.