Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Latest commit

 

History

History
298 lines (203 loc) · 9.91 KB

File metadata and controls

298 lines (203 loc) · 9.91 KB

MutationContext<T> ..

Describes the context in which mutation is performed.

Namespace: Dado.ComponentModel.DataMutations
Implements: Dado.ComponentModel.DataMutations.IMutationContext (in Dado.ComponentModel.Mutations)

Syntax

public sealed class MutationContext<T> : IMutationContext
T
The type to consult during mutation.

Remarks

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>.

Constructors

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.

Properties

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.

Methods

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.

Explicit Interface Implementations

Name Description
IMutationContext.ObjectInstance Gets the instance being mutated.

Extension Methods

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.

MutationContext<T>(T)

Initializes a new instance of the MutationContext<T> class for a given object instance.

public MutationContext(
	T instance
)

Parameters

instance
Type: `T
The instance to be modified during mutation.

Exceptions

Exception Condition
System.ArgumentNullException When instance is null.

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.

public MutationContext(
	T instance,
	IDictionary<object, object> items
)

Parameters

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.

Exceptions

Exception Condition
System.ArgumentNullException When instance is null.

MutationContext<T>(T, IServiceProvider)

Initializes a new instance of the MutationContext<T> class for a given object instance and a serviceProvider.

public MutationContext(
	T instance,
	IServiceProvider serviceProvider
)

Parameters

instance
Type: `T
The instance to be modified during mutation.
serviceProvider
Type: System.IServiceProvider
A IServiceProvider to use when GetService is called.

Exceptions

Exception Condition
System.ArgumentNullException When instance is null.

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.

public MutationContext(
	T instance,
	IDictionary<object, object> items,
	IServiceProvider serviceProvider
)

Parameters

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.

Exceptions

Exception Condition
System.ArgumentNullException When instance is null.

Attributes

Gets the attributes associated with this context.

Syntax

IEnumerable<Attribute> Attributes { get; }
Type
System.Collections.Generic<System.Attribute>

Items

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>

Property Value

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.

ObjectInstance

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

Remarks

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.

GetService(Type)

Returns the service that provides custom mutation.

public object GetService(
	Type serviceType
)

Returns

An instance of that service or null if it is not available.

Parameters

serviceType
Type: System.Type
The type of the service needed.

InitializeServiceProvider(Func<Type, object>)

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
)

Parameters

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.

IMutationContext.ObjectInstance

Gets the instance being mutated.

object IMutationContext.ObjectInstance { get; }
Type
System.Object