Show / Hide Table of Contents

# Class StateTransitionTransaction

A class to represent a transaction for changing the state of loaded mods.

##### Inheritance

Object
StateTransitionTransaction

##### Implements

IDisposable

##### Inherited Members

Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()

###### Namespace: IPA.Loader

###### Assembly: IPA.Loader.dll

##### Syntax

    public sealed class StateTransitionTransaction : IDisposable

### Properties

| Improve this Doc View Source

#### DisabledPlugins

Gets a list of plugins that are disabled according to this transaction's current state.

##### Declaration

    public IEnumerable<PluginMetadata> DisabledPlugins { get; }

##### Property Value

Type | Description
--- | ---
IEnumerable<PluginMetadata> |

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

| Improve this Doc View Source

#### EnabledPlugins

Gets a list of plugins that are enabled according to this transaction's current state.

##### Declaration

    public IEnumerable<PluginMetadata> EnabledPlugins { get; }

##### Property Value

Type | Description
--- | ---
IEnumerable<PluginMetadata> |

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

| Improve this Doc View Source

#### HasStateChanged

Gets whether or not the current state has changed.

##### Declaration

    public bool HasStateChanged { get; }

##### Property Value

Type | Description
--- | ---
Boolean | true if the current state of the transaction is different from its construction, false otherwise

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

| Improve this Doc View Source

#### WillNeedRestart

Gets whether or not a game restart will be necessary to fully apply this transaction.

##### Declaration

    public bool WillNeedRestart { get; }

##### Property Value

Type | Description
--- | ---
Boolean | true if any mod who's state is changed cannot be changed at runtime, false otherwise

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

### Methods

| Improve this Doc View Source

#### Clone()

Clones this transaction to be identical, but with unrelated underlying sets.

##### Declaration

    public StateTransitionTransaction Clone()

##### Returns

Type | Description
--- | ---
StateTransitionTransaction | the new StateTransitionTransaction

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

| Improve this Doc View Source

#### Commit()

Commits this transaction to actual state, enabling and disabling plugins as necessary.

##### Declaration

    public Task Commit()

##### Returns

Type | Description
--- | ---
Task | a Task which completes whenever all disables complete

##### Remarks

After this completes, this transaction will be disposed.

The Task that is returned will error if any of the mods being disabled error. It is up to the caller to handle these in a sane way, like logging them. If nothing else, do something like this:

    // get your transaction...
    var complete = transaction.Commit();
    await complete.ContinueWith(t => {
        if (t.IsFaulted)
            Logger.log.Error($"Error disabling plugins: {t.Exception}");
    });

If you are running in a coroutine, you can use WaitForTask(Task) instead of await.

If you are running on the Unity main thread, this will block until all enabling is done, and will return a task representing the disables. Otherwise, the task returned represents both, and will not complete until Unity has done (possibly) several updates, depending on the number of plugins being disabled, and the time they take.

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed
InvalidOperationException | if the plugins' state no longer matches this transaction's original state

| Improve this Doc View Source

#### Disable(PluginMetadata, Boolean)

Disables a plugin in this transaction.

##### Declaration

    public bool Disable(PluginMetadata meta, bool autoDependents = true)

##### Parameters

Type | Name | Description
--- | --- | ---
PluginMetadata | meta | the plugin to disable
Boolean | autoDependents | whether or not to automatically disable all dependents of the plugin

##### Returns

Type | Description
--- | ---
Boolean | true if the transaction's state was changed, false otherwise

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed
ArgumentException | if `meta` is not loadable

##### See Also

Disable(PluginMetadata, out IEnumerable<PluginMetadata>, Boolean)
| Improve this Doc View Source

#### Disable(PluginMetadata, out IEnumerable<PluginMetadata>, Boolean)

Disables a plugin in this transaction.

##### Declaration

    public bool Disable(PluginMetadata meta, out IEnumerable<PluginMetadata> enabledDependents, bool autoDependents = false)

##### Parameters

Type | Name | Description
--- | --- | ---
PluginMetadata | meta | the plugin to disable
IEnumerable<PluginMetadata> | enabledDependents | null if successful, otherwise a set of plugins that need to be disabled first
Boolean | autoDependents | whether or not to automatically disable all dependents of the plugin

##### Returns

Type | Description
--- | ---
Boolean | true if the transaction's state was changed, false otherwise

##### Remarks

`enabledDependents` will only be set when `autoDependents` is false.

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed
ArgumentException | if `meta` is not loadable

| Improve this Doc View Source

#### Dispose()

Disposes and discards this transaction without committing it.

##### Declaration

    public void Dispose()

| Improve this Doc View Source

#### Enable(PluginMetadata, Boolean)

Enables a plugin in this transaction.

##### Declaration

    public bool Enable(PluginMetadata meta, bool autoDeps = true)

##### Parameters

Type | Name | Description
--- | --- | ---
PluginMetadata | meta | the plugin to enable
Boolean | autoDeps | whether or not to automatically enable all dependencies of the plugin

##### Returns

Type | Description
--- | ---
Boolean | true if the transaction's state was changed, false otherwise

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed
ArgumentException | if `meta` is not loadable

##### See Also

Enable(PluginMetadata, out IEnumerable<PluginMetadata>, Boolean)
| Improve this Doc View Source

#### Enable(PluginMetadata, out IEnumerable<PluginMetadata>, Boolean)

Enables a plugin in this transaction.

##### Declaration

    public bool Enable(PluginMetadata meta, out IEnumerable<PluginMetadata> disabledDeps, bool autoDeps = false)

##### Parameters

Type | Name | Description
--- | --- | ---
PluginMetadata | meta | the plugin to enable
IEnumerable<PluginMetadata> | disabledDeps | null if successful, otherwise a set of plugins that need to be enabled first
Boolean | autoDeps | whether or not to automatically enable all dependencies

##### Returns

Type | Description
--- | ---
Boolean | true if the transaction's state was changed, false otherwise

##### Remarks

`disabledDeps` will only be set when `autoDeps` is false.

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed
ArgumentException | if `meta` is not loadable

| Improve this Doc View Source

#### IsDisabled(PluginMetadata)

Checks if a plugin is disabled according to this transaction's current state.

##### Declaration

    public bool IsDisabled(PluginMetadata meta)

##### Parameters

Type | Name | Description
--- | --- | ---
PluginMetadata | meta | the plugin to check

##### Returns

Type | Description
--- | ---
Boolean | true if the plugin is disabled, false otherwise

##### Remarks

This should be roughly equivalent to `DisabledPlugins.Contains(meta)`, but more performant.

This should also always return the inverse of IsEnabled(PluginMetadata) for valid plugins.

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

##### See Also

DisabledPlugins
IsEnabled(PluginMetadata)
| Improve this Doc View Source

#### IsEnabled(PluginMetadata)

Checks if a plugin is enabled according to this transaction's current state.

##### Declaration

    public bool IsEnabled(PluginMetadata meta)

##### Parameters

Type | Name | Description
--- | --- | ---
PluginMetadata | meta | the plugin to check

##### Returns

Type | Description
--- | ---
Boolean | true if the plugin is enabled, false otherwise

##### Remarks

This should be roughly equivalent to `EnabledPlugins.Contains(meta)`, but more performant.

This should also always return the inverse of IsDisabled(PluginMetadata) for valid plugins.

##### Exceptions

Type | Condition
--- | ---
ObjectDisposedException | if this object has been disposed

##### See Also

EnabledPlugins
IsDisabled(PluginMetadata)

### Implements

System.IDisposable

### Extension Methods

ReflectionUtil.SetField<T, U>(T, String, U)
ReflectionUtil.GetField<U, T>(T, String)
ReflectionUtil.SetProperty<T, U>(T, String, U)
ReflectionUtil.GetProperty<U, T>(T, String)
ReflectionUtil.InvokeMethod<U, T>(T, String, Object[])