# TaskIdExtensions Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.taskidextensions/)

## ToHierarchicalKey(TaskId) {#tohierarchicalkey-this-orleans-durable-tasks-taskid-11f97919}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.taskidextensions/methods/tohierarchicalkey-this-orleans-durable-tasks-taskid-11f97919/)

[Source](https://github.com/dotnet/orleans/blob/6a0e937f544c35ffcf11b37e4c2b7de5a1580a03/src/Orleans.Durable/DurableTasks/Protocol/TaskIdExtensions.cs#L33)

```csharp
public static HierarchicalKey? ToHierarchicalKey(this TaskId taskId)
```

Converts a [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) to a [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/).

### Parameters

- `taskId` (`TaskId`): The [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) to convert.

### Returns

A [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/) equivalent to the specified [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/), or `null` if the [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) is the default value.

### Examples

```csharp
TaskId taskId = TaskId.Parse("workflow/task-123");
            Orleans.Durable.Messaging.HierarchicalKey? key = taskId.ToHierarchicalKey();
            // key.ToString() == "workflow/task-123"
```

## ToTaskId(HierarchicalKey) {#totaskid-this-orleans-durable-messaging-hierarchicalkey-4521b2e1}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.taskidextensions/methods/totaskid-this-orleans-durable-messaging-hierarchicalkey-4521b2e1/)

[Source](https://github.com/dotnet/orleans/blob/6a0e937f544c35ffcf11b37e4c2b7de5a1580a03/src/Orleans.Durable/DurableTasks/Protocol/TaskIdExtensions.cs)

```csharp
public static TaskId ToTaskId(this HierarchicalKey key)
```

Converts a [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/) to a [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/).

### Parameters

- `key` (`HierarchicalKey`): The [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/) to convert.

### Returns

A [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) equivalent to the specified [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/), or [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) if the key is unset.

### Examples

```csharp
Orleans.Durable.Messaging.HierarchicalKey key =
                Orleans.Durable.Messaging.HierarchicalKey.Parse("workflow/task-123", null);
            TaskId taskId = key.ToTaskId();
            // taskId.ToString() == "workflow/task-123"
```

## ToTaskId(HierarchicalKey?) {#totaskid-this-orleans-durable-messaging-hierarchicalkey-nullable-2fd1e1dc}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.taskidextensions/methods/totaskid-this-orleans-durable-messaging-hierarchicalkey-nullable-2fd1e1dc/)

[Source](https://github.com/dotnet/orleans/blob/6a0e937f544c35ffcf11b37e4c2b7de5a1580a03/src/Orleans.Durable/DurableTasks/Protocol/TaskIdExtensions.cs)

```csharp
public static TaskId ToTaskId(this HierarchicalKey? key)
```

Converts a nullable [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/) to a [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/).

### Parameters

- `key` (`HierarchicalKey?`): The [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/) to convert.

### Returns

A [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) equivalent to the specified [HierarchicalKey](/orleans/docs/api/csharp/microsoft.orleans.durable/orleans.durable.messaging.hierarchicalkey/), or [TaskId](/orleans/docs/api/csharp/microsoft.orleans.durable.abstractions/orleans.durable.tasks.taskid/) if the key is `null` or unset.
