![]() | BuilderT Class |
Namespace: Capgemini.CommonObjectUtils
The BuilderT type exposes the following members.
Name | Description | |
---|---|---|
![]() | Build |
Builds the target object.
|
![]() | BuildImplementation |
The internal implementation that builds the target object.
|
![]() | Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Expect |
Tells the builder that an argument is expected.
|
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | Got |
Checks if an argument has received.
|
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ReceiveTArg |
Tells the builder that an argument was received.
|
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
You can inherit from this class when writing your own builders.
Call the Expect(String, BuilderTNecessity) method to tell the class what arguments your builder needs and which ones are mandatory.
Call the ReceiveTArg(String, TArg) method as your builder gets each argument to tell the builder which arguments you have received.
When client code calls the Build method the Builder class will check that all mandatory arguments have beens supplied and if they haven't it will throw a MissingBuilderArgumentException. If all the required arguments have been supplied the builder calls the BuildImplementation method that the sub-class supplies and building finishes.
If you need to know if a particular argument got supplied you can call the Got(String) method instead of tracking that yourself.
private class IntBuilder : Builder<int> { private int value; private int multiplier; public IntBuilder() { Expect("value", Necessity.Mandatory); Expect("multiplier", Necessity.Optional); } public IntBuilder SetValue(int value) { this.value = Receive("value", value); return this; } public IntBuilder SetMultiplier(int multiplier) { this.multiplier = Receive("multiplier", multiplier); return this; } protected override int BuildImplementation() { return value * (Got("multiplier") ? multiplier : 1); } }