Class Factory<TBlueprintID, TProduced>
A simple factory that produces a type of object based on a blueprint.
Inherited Members
Namespace: GoRogue.Factories
Assembly: GoRogue.dll
Syntax
[DataContract]
public class Factory<TBlueprintID, TProduced> : IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>>, IEnumerable where TBlueprintID : notnull
Type Parameters
Name | Description |
---|---|
TBlueprintID | The type used to uniquely identify blueprints. |
TProduced | The type of object this factory creates. |
Constructors
View SourceFactory()
Constructor.
Declaration
public Factory()
Factory(IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>>)
Constructor. Takes initial blueprints to add.
Declaration
public Factory(IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>> initialBlueprints)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>> | initialBlueprints | Initial blueprints to add. |
Methods
View SourceAdd(IFactoryBlueprint<TBlueprintID, TProduced>)
Adds a blueprint to the factory.
Declaration
public void Add(IFactoryBlueprint<TBlueprintID, TProduced> blueprint)
Parameters
Type | Name | Description |
---|---|---|
IFactoryBlueprint<TBlueprintID, TProduced> | blueprint | The blueprint to add. |
AddRange(IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>>)
Adds the given blueprints to the factory.
Declaration
public void AddRange(IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>> blueprints)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IFactoryBlueprint<TBlueprintID, TProduced>> | blueprints | The blueprints to add. |
BlueprintExists(TBlueprintID)
Checks if a blueprint exists.
Declaration
public bool BlueprintExists(TBlueprintID blueprintID)
Parameters
Type | Name | Description |
---|---|---|
TBlueprintID | blueprintID | The blueprint to check for. |
Returns
Type | Description |
---|---|
bool | Returns true when the specified |
Create(TBlueprintID)
Creates a TProduced
object using the blueprint with the given factory id.
Declaration
public TProduced Create(TBlueprintID blueprintID)
Parameters
Type | Name | Description |
---|---|---|
TBlueprintID | blueprintID | The factory id of a blueprint. |
Returns
Type | Description |
---|---|
TProduced | A new object. |
GetBlueprint(TBlueprintID)
Gets a blueprint by identifier.
Declaration
public IFactoryBlueprint<TBlueprintID, TProduced> GetBlueprint(TBlueprintID blueprintID)
Parameters
Type | Name | Description |
---|---|---|
TBlueprintID | blueprintID | The blueprint identifier to get. |
Returns
Type | Description |
---|---|
IFactoryBlueprint<TBlueprintID, TProduced> | The blueprint of the object. |
Exceptions
Type | Condition |
---|---|
ItemNotDefinedException<TBlueprintID> | Thrown if the factory identifier does not exist. |
GetEnumerator()
Gets an enumerator of all of the blueprints in the factory.
Declaration
public IEnumerator<IFactoryBlueprint<TBlueprintID, TProduced>> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<IFactoryBlueprint<TBlueprintID, TProduced>> | An enumeration of the blueprints. |