public static void ValidateToSchema( object item )
{
MethodInfo miValidate = item.GetType().GetMethod( "Validate" );
if (miValidate == null)
throw new Exception( string.Format( "{0} does not support the Validate Method", item.GetType().Name ) );
var errors = new SchemaValidationResult();
object[] p = {errors};
miValidate.Invoke( item, p );
if (errors.HasErrors())
{
throw new Exception( string.Format(
"This {0} has failed validation against the ATML Schema with the following errors:\n{1}",
item.GetType().Name, errors.ErrorMessage ) );
}
MessageBox.Show( string.Format(
"This {0} has passed all validation against the ATML Schema.",
item.GetType().Name ), @"V a l i d a t i o n", MessageBoxButtons.OK, MessageBoxIcon.Information );
}