annotate api/Objects/InvalidContainershipException.cs @ 61:3c77722a02b5

Re #61 - Complete structure of WarFoundry API objects * Add containership support to Unit class * Add method to UnitType to check if a UnitType is of an allowed type
author IBBoard <dev@ibboard.co.uk>
date Thu, 09 Apr 2009 14:17:53 +0000
parents
children 2f3cafb69799
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (InvalidContainershipException.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2009 IBBoard
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // The file and the library/program it is in are licensed under the GNU LGPL license, either version 3 of the License or (at your option) any later version. Please see COPYING.LGPL for more information and the full license.
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 //
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using System;
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 namespace IBBoard.WarFoundry.API.Objects
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 /// <summary>
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 /// A custom exception for when a unit was added as a sub-unit of another unit, but was not of a <see cref=" UnitType"/> that can be contained
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 /// by that unit.
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 /// </summary>
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class InvalidContainershipException : Exception
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 private Unit containing;
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 private Unit contained;
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 public InvalidContainershipException(Unit containingUnit, Unit containedUnit) : base(CreateMessageString(containingUnit, containedUnit))
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 containing = containingUnit;
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 contained = containedUnit;
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 private static string CreateMessageString(Unit containingUnit, Unit containedUnit)
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 return containingUnit.Name+" cannot contain "+containedUnit.Name+" because units of "+containingUnit.UnitType.Name+" cannot contain units of "+containedUnit.UnitType.Name;
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 /// <value>
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 /// The <see cref=" Unit"/> that the contained unit was added to
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 /// </value>
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 public Unit ContainingUnit
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 get { return containing; }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 /// <value>
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 /// The <see cref=" Unit"/> that was added as a contained unit, but which was not of an allowed type
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 /// </value>
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 public Unit ContainedUnit
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 {
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 get { return contained; }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 }
3c77722a02b5 Re #61 - Complete structure of WarFoundry API objects
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 }