Skip to content

Instantly share code, notes, and snippets.

@wattsm
Created May 22, 2012 08:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wattsm/2767581 to your computer and use it in GitHub Desktop.
Save wattsm/2767581 to your computer and use it in GitHub Desktop.
Predefined Validation Rules
public class PredefinedRulesSchema : IMessageSchemaProvider {
public MessageSchema GetSchema() {
return MessageSchema.Named("validated-message")
.WithRootName("Validated")
.WithProperty(
MessageSchemaProperty.Named("BooleanProperty")
.IsBoolean(BooleanTypes.YN)
)
.WithProperty(
MessageSchemaProperty.Named("PatternProperty")
.Matches("^(N[0-9]+)$", RegexOptions.IgnoreCase)
)
.WithProperty(
MessageSchemaProperty.Named("RequiredProperty")
.IsRequired()
)
.WithProperty(
MessageSchemaProperty.Named("ShortProperty")
.MaxLength(10)
)
.WithProperty(
MessageSchemaProperty.Named("RegexProperty")
.IsRequired()
.Matches("^(([A-F]{3})([0-9]{3}))$")
)
.WithProperty(
MessageSchemaProperty.Named("IntegralProperty")
.IsIntegral(0, null)
)
.WithProperty(
MessageSchemaProperty.Named("TimeProperty")
.IsDateTime("HH:mm")
)
.WithPart(
MessageSchemaPart.OfType<ValidatedSubMessage>("Sub")
.IsRequired()
)
.WithCollection(
MessageSchemaCollection.OfType<ValidatedSubMessage>("SubItems")
.Size(0, 2)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment