Class PropertyBag<TContainer>
Base class for implementing a property bag for a specified container type. This is an abstract class.
Inherited Members
Namespace: Unity.Properties
Syntax
public abstract class PropertyBag<TContainer> : IPropertyBag<TContainer>, IPropertyBag, IPropertyBagRegister, IConstructor<TContainer>, IConstructor
Type Parameters
Name | Description |
---|---|
TContainer | The container type. |
Remarks
This is used as the base class internally and should NOT be extended.
When implementing custom property bags use:
Properties
InstantiationKind
Implement this property and return true to provide custom type instantiation for the container type.
Declaration
protected virtual InstantiationKind InstantiationKind { get; }
Property Value
Type | Description |
---|---|
InstantiationKind |
Methods
Accept(ITypeVisitor)
Accepts visitation from a specified ITypeVisitor.
Declaration
public void Accept(ITypeVisitor visitor)
Parameters
Type | Name | Description |
---|---|---|
ITypeVisitor | visitor | The visitor handling visitation. |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The visitor is null. |
CreateInstance()
Creates and returns a new instance of
Declaration
public TContainer CreateInstance()
Returns
Type | Description |
---|---|
TContainer | A new instance of |
Implements
GetProperties()
Implement this method to return a PropertyCollection<TContainer> that can enumerate through all properties for the TContainer
.
Declaration
public abstract PropertyCollection<TContainer> GetProperties()
Returns
Type | Description |
---|---|
PropertyCollection<TContainer> | A PropertyCollection<TContainer> structure which can enumerate each property. |
GetProperties(ref TContainer)
Implement this method to return a PropertyCollection<TContainer> that can enumerate through all properties for the TContainer
.
Declaration
public abstract PropertyCollection<TContainer> GetProperties(ref TContainer container)
Parameters
Type | Name | Description |
---|---|---|
TContainer | container | The container hosting the data. |
Returns
Type | Description |
---|---|
PropertyCollection<TContainer> | A PropertyCollection<TContainer> structure which can enumerate each property. |
Instantiate()
Implement this method to provide custom type instantiation for the container type.
Declaration
protected virtual TContainer Instantiate()
Returns
Type | Description |
---|---|
TContainer | A new instance of |
Remarks
You MUST also override InstantiationKind to return langword_csharp_ConstructionType.PropertyBagOverride for this method to be called.
TryCreateInstance(out TContainer)
Tries to create a new instance of
Declaration
public bool TryCreateInstance(out TContainer instance)
Parameters
Type | Name | Description |
---|---|---|
TContainer | instance | When this method returns, contains the created instance, if type instantiation succeeded; otherwise, the default value for |
Returns
Type | Description |
---|---|
Boolean | true if a new instance of type |
Implements
Explicit Interface Implementations
IPropertyBag.Accept(IPropertyBagVisitor, ref Object)
Accepts visitation from a specified IPropertyBagVisitor using an object as the container.
Declaration
void IPropertyBag.Accept(IPropertyBagVisitor visitor, ref object container)
Parameters
Type | Name | Description |
---|---|---|
IPropertyBagVisitor | visitor | The visitor handling the visitation. |
Object | container | The container being visited. |
Implements
Exceptions
Type | Condition |
---|---|
ArgumentNullException | The container is null. |
InvalidCastException | The container type does not match the property bag type. |
IPropertyBag<TContainer>.Accept(IPropertyBagVisitor, ref TContainer)
Accepts visitation from a specified IPropertyBagVisitor using a strongly typed container.
Declaration
void IPropertyBag<TContainer>.Accept(IPropertyBagVisitor visitor, ref TContainer container)
Parameters
Type | Name | Description |
---|---|---|
IPropertyBagVisitor | visitor | The visitor handling the visitation. |
TContainer | container | The container being visited. |
Implements
IPropertyBag<TContainer>.GetProperties()
Returns an enumerator that iterates through all static properties for the type.
Declaration
PropertyCollection<TContainer> IPropertyBag<TContainer>.GetProperties()
Returns
Type | Description |
---|---|
PropertyCollection<TContainer> | A IEnumerator<T> structure for all properties. |
Implements
Remarks
This should return a subset properties returned by GetProperties(ref TContainer).
IPropertyBag<TContainer>.GetProperties(ref TContainer)
Returns an enumerator that iterates through all static and dynamic properties for the given container.
Declaration
PropertyCollection<TContainer> IPropertyBag<TContainer>.GetProperties(ref TContainer container)
Parameters
Type | Name | Description |
---|---|---|
TContainer | container | The container hosting the data. |
Returns
Type | Description |
---|---|
PropertyCollection<TContainer> | A IEnumerator<T> structure for all properties. |
Implements
Remarks
This should return all static properties returned by GetProperties() in addition to any dynamic properties. If the container is a collection type all elements will be iterated.