MutationContext<T> ..
Describes the context in which mutation is performed.
Namespace: Dado.ComponentModel.DataMutations
Implements: Dado.ComponentModel.DataMutations.IMutationContext (in Dado.ComponentModel.Mutations)
public sealed class MutationContext<T> : IMutationContext- T
- The type to consult during mutation.
This class contains information describing the instance on which mutation is performed.
An Items property bag is available for additional contextual information about the mutation. Values stored in Items will be available to mutation methods that use this MutationContext<T>.
| Name | Description |
|---|---|
| MutationContext<T>(T) | Initializes a new instance of the MutationContext<T> class for a given object instance. |
| MutationContext<T>(T, IDictionary<object, object>) | Initializes a new instance of the MutationContext<T> class for a given object instance and a property bag of items. |
| MutationContext<T>(T, IServiceProvider) | Initializes a new instance of the MutationContext<T> class for a given object instance and a serviceProvider. |
| MutationContext<T>(T, IDictionary<object, object>, IServiceProvider) | Initializes a new instance of the MutationContext<T> class for a given object instance, a serviceProvider, and a property bag of items. |
| Name | Description |
|---|---|
| Attributes | Gets the attributes associated with this context. |
| Items | Gets the dictionary of key/value pairs associated with this context. |
| ObjectInstance | Gets the instance being mutated. |
| Name | Description |
|---|---|
| GetService(Type) | Returns the service that provides custom mutation. |
| InitializeServiceProvider(Func<Type, object>) | Initializes the MutationContext<T> with a service provider that can return service instances by Type when GetService is called. |
| Name | Description |
|---|---|
| IMutationContext.ObjectInstance | Gets the instance being mutated. |
| Name | Description |
|---|---|
| Mutate<T>() | Mutates the instance associated with the current context. |
| Mutate<T>(IEnumerable<MutationAttribute>) | Mutates the value or instance associated with the current context and the specified MutationAttributes. |
| Mutate<T>(IEnumerable<MutationAttribute>, T) | Mutates the specified value against the current context and the specified MutationAttributes. |
| Mutate<T>(T) | Mutates the specified instance against the current context. |
| Mutate<T>(T, IEnumerable<MutationAttribute>) | Mutates the specified instance against the current context and the specified MutationAttributes. |
| MutateProperty<T>(PropertyInfo) | Mutates the specified property of the instance associated with the current context. |
| MutateProperty<T, P>(PropertyInfo, P) | Mutates the specified value against the specified property of the instance associated with the current context. |
| MutateProperty<T, P>(Expression<Func<T, P>>) | Mutates the specified property of the instance associated with the current context. |
| MutateProperty<T, P>(Expression<Func<T, P>>, P) | Mutates the specified value against the specified property of the instance associated with the current context. |
Initializes a new instance of the MutationContext<T> class for a given object instance.
public MutationContext(
T instance
)- instance
- Type: `T
The instance to be modified during mutation.
| Exception | Condition |
|---|---|
| System.ArgumentNullException | When instance is null. |
Initializes a new instance of the MutationContext<T> class for a given object instance and a property bag of items.
public MutationContext(
T instance,
IDictionary<object, object> items
)- instance
- Type: `T
The instance to be modified during mutation. - items
- Type: System.Collections.Generic.IDictionary<System.Object, System.Object>
A set of key/value pairs to make available to consumers via Items. The set of key/value pairs will be copied into a new dictionary, preventing consumers from modifying the original dictionary.
| Exception | Condition |
|---|---|
| System.ArgumentNullException | When instance is null. |
Initializes a new instance of the MutationContext<T> class for a given object instance and a serviceProvider.
public MutationContext(
T instance,
IServiceProvider serviceProvider
)- instance
- Type: `T
The instance to be modified during mutation. - serviceProvider
- Type: System.IServiceProvider
A IServiceProvider to use when GetService is called.
| Exception | Condition |
|---|---|
| System.ArgumentNullException | When instance is null. |
Initializes a new instance of the MutationContext<T> class for a given object instance, a serviceProvider, and a property bag of items.
public MutationContext(
T instance,
IDictionary<object, object> items,
IServiceProvider serviceProvider
)- instance
- Type: `T
The instance to be modified during mutation. - items
- Type: System.Collections.Generic.IDictionary<System.Object, System.Object>
A set of key/value pairs to make available to consumers via Items. The set of key/value pairs will be copied into a new dictionary, preventing consumers from modifying the original dictionary. - serviceProvider
- Type: System.IServiceProvider
A IServiceProvider to use when GetService is called.
| Exception | Condition |
|---|---|
| System.ArgumentNullException | When instance is null. |
Gets the attributes associated with this context.
IEnumerable<Attribute> Attributes { get; }- Type
- System.Collections.Generic<System.Attribute>
Gets the dictionary of key/value pairs associated with this context.
public IDictionary<object, object> Items { get; }- Type
- System.Collections.Generic.IDictionary<System.Object, System.Object>
This property will never be null, but the dictionary may be empty. Changes made to items in this dictionary will never affect the original dictionary specified in the constructor.
Gets the instance being mutated. While it will not be null, the state of the instance is indeterminate as it might only be partially initialized during mutation.
Consume this instance with caution!
public T ObjectInstance { get; }- Type
- `T
During mutation, especially property-level mutation, the instance might be in a indeterminate state. For example, the property being mutated, as well as other properties on the instance might not have been updated to their new values.
Returns the service that provides custom mutation.
public object GetService(
Type serviceType
)An instance of that service or null if it is not available.
- serviceType
- Type: System.Type
The type of the service needed.
Initializes the MutationContext<T> with a service provider that can return service instances by Type when GetService is called.
public void InitializeServiceProvider(
Func<Type, object> serviceProvider
)- serviceProvider
- Type: System.Func<System.Type, System.Object>
A Func<Type, object> that can return service instances given the desired Type when GetService is called. If it is null, GetService will always return null.
Gets the instance being mutated.
object IMutationContext.ObjectInstance { get; }- Type
- System.Object