Mercurial > repos > snowblizz-super-API-ideas
changeset 339:50cd43bf51b3
Re #27: Unit requirements
* Add tri-state enum (passed, failed, not applicable) and helper class
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 19:40:42 +0000 |
parents | 4497ebce9a57 |
children | 7bd2a7cdbfbd |
files | API/Objects/Requirement/Validation.cs IBBoard.WarFoundry.API.csproj |
diffstat | 2 files changed, 56 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/Validation.cs Sun Apr 03 19:40:42 2011 +0000 @@ -0,0 +1,54 @@ +// This file (Validation.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2011 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + /// <summary> + /// A custom enum for validation to distinguish between "validation wasn't necessary" and "validation passed". + /// This should allow for easier handling of failed requirements later being satisfied. + /// </summary> + public enum Validation + { + Passed = 1, + Failed = 2, + NotApplicable = 3 + } + + /// <summary> + /// A helper class to handle the enums and treat them as booleans where a pass/fail is all that is necessary. + /// </summary> + public class Validates + { + /// <summary> + /// Checks if the validation was okay (pass or not applicable) + /// </summary> + /// <returns> + /// <code>true</code> if the validation passed or was not applicable, else <code>false</code> + /// </returns> + /// <param name='passed'> + /// The Validation enum value to check + /// </param> + public static bool AsOkay(Validation result) + { + return (result | Validation.Passed) == Validation.Passed; + } + + /// <summary> + /// Checks if the validation result was not okay (failed or not applicable). Note that this is different + /// to <code>!Validates.AsOkay(result)</code> because this method treats not applicable as not being okay. + /// </summary> + /// <returns> + /// <code>true</code> if the validation failed or was not applicable, else <code>false</code> + /// </returns> + /// <param name='result'> + /// The Validation enum value to check + /// </param> + public static bool AsNotOkay (Validation result) + { + return (result | Validation.Failed) == Validation.Failed; + } + } +} +
--- a/IBBoard.WarFoundry.API.csproj Sun Apr 03 19:03:30 2011 +0000 +++ b/IBBoard.WarFoundry.API.csproj Sun Apr 03 19:40:42 2011 +0000 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> @@ -189,6 +189,7 @@ <Compile Include="API\Objects\Requirement\UnitCountRequirementData.cs" /> <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirement.cs" /> <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirement.cs" /> + <Compile Include="API\Objects\Requirement\Validation.cs" /> </ItemGroup> <ItemGroup> <Reference Include="System.Xml" />