Last active
August 29, 2015 13:58
-
-
Save ianfnelson/9991359 to your computer and use it in GitHub Desktop.
Snippets for 2009 blog post "Code Contracts"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Search for a collection of customers, given a set of criteria. | |
/// </summary> | |
/// <param name="queryCriteria" />Query Object defining the search criteria.</param> | |
/// <returns>Collection of customers matching the specified criteria.</returns> | |
/// <exception cref="System.ArgumentNullException">Where queryCriteria is null</exception> | |
/// <exception cref="System.ArgumentException">Where no query criteria have been set (we do not permit searching for all customers)</exception> | |
public static CustomerCollection Find(CustomerQuery queryCriteria) | |
{ | |
#region Validate parameters | |
// Guard clause 1 - null queryCriteria - throw exception | |
if ( queryCriteria == null ) throw new ArgumentNullException( "queryCriteria" ); | |
// Guard clause 2 - no query criteria specified - throw exception | |
if ( !queryCriteria.IsUsed( SourceSystem.All ) ) throw new ArgumentException( ExceptionMessages.BusinessLogic_CustomerRepository_Find_NoCriteriaSpecified, "queryCriteria" ); | |
#endregion | |
// More stuff here to return customers | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Guard clause 1 - null queryCriteria | |
Contract.Requires( queryCriteria!=null ); | |
// Guard clause 2 - no query criteria specified | |
Contract.Requires( queryCriteria.IsUsed( SourceSystem.All ), ExceptionMessages.BusinessLogic_CustomerRepository_Find_NoCriteriaSpecified); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment