> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/scene-fusion/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/scene-fusion/api-reference/ks.scenefusion.client.unity.editor/ks.scenefusion.client.unity.editor.sfdependencysorter-1.md).

# Class sfDependencySorter\<T>

Namespace: [KS.SceneFusion.Client.Unity.Editor](/scene-fusion/api-reference/ks.scenefusion.client.unity.editor.md)\
Assembly: KSUnity-Source.dll

Stores a map of dependencies between elements of type `T`, and provides a method for sorting the elements so all dependencies of A are iterated before A. Elements without dependencies will not be iterated, eg. If A depends on B and C and B depends on D, B will be iterated and then A, but C and D will not because they have no dependencies. Circular dependencies are not allowed.

```csharp
public class sfDependencySorter<T>
```

#### Type Parameters

`T`

Type of object to track dependencies for.

#### Inheritance

object ← [sfDependencySorter\<T>](/scene-fusion/api-reference/ks.scenefusion.client.unity.editor/ks.scenefusion.client.unity.editor.sfdependencysorter-1.md)

## Properties

### Count <a href="#ks_scenefusion_client_unity_editor_sfdependencysorter_1_count" id="ks_scenefusion_client_unity_editor_sfdependencysorter_1_count"></a>

The number of elements with dependencies.

```csharp
public int Count { get; }
```

#### Property Value

int

## Methods

### Add(T, T) <a href="#ks_scenefusion_client_unity_editor_sfdependencysorter_1_add__0__0" id="ks_scenefusion_client_unity_editor_sfdependencysorter_1_add__0__0"></a>

Adds a dependency from `item` to `dependency`.

```csharp
public bool Add(T item, T dependency)
```

#### Parameters

`item` T

Item that depends on `dependency`

`dependency` T

Dependency that `item` depends on.

#### Returns

bool

False if the dependency was not added because it would create a circular dependency.

### Clear() <a href="#ks_scenefusion_client_unity_editor_sfdependencysorter_1_clear" id="ks_scenefusion_client_unity_editor_sfdependencysorter_1_clear"></a>

Clears all dependencies.

```csharp
public void Clear()
```

### DependsOn(T, T) <a href="#ks_scenefusion_client_unity_editor_sfdependencysorter_1_dependson__0__0" id="ks_scenefusion_client_unity_editor_sfdependencysorter_1_dependson__0__0"></a>

Checks if `item` depends on `dependencyCheck`. Dependencies are transitive so if A depends on B and B depends on C, then A depends on C.

```csharp
public bool DependsOn(T item, T dependencyCheck)
```

#### Parameters

`item` T

Item to check dependencies for.

`dependencyCheck` T

Dependency to check for.

#### Returns

bool

True if `item` depends on `dependencyCheck`.

### GetEnumerator() <a href="#ks_scenefusion_client_unity_editor_sfdependencysorter_1_getenumerator" id="ks_scenefusion_client_unity_editor_sfdependencysorter_1_getenumerator"></a>

Gets an enumerator to iterate the sorted elements with dependencies. [Sort](#ks_scenefusion_client_unity_editor_sfdependencysorter_1_sort).

```csharp
public IEnumerator<T> GetEnumerator()
```

#### Returns

IEnumerator\<T>

Enumerator

### Sort() <a href="#ks_scenefusion_client_unity_editor_sfdependencysorter_1_sort" id="ks_scenefusion_client_unity_editor_sfdependencysorter_1_sort"></a>

Returns a sorted list of dependencies such that all dependencies of an element occur in the list before that element. Dependencies that do not themselves have any dependencies are not included in the list.

```csharp
public List<T> Sort()
```

#### Returns

List\<T>

Sorted list of elements with dependencies.
