# ReferenceExpression Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md)
- Kind: `Methods`
- Members: `4`

Represents an expression that might be made up of multiple resource properties. For example, a connection string might be made up of a host, port, and password from different endpoints.

## Create(ExpressionInterpolatedStringHandler)

- Name: `Create(ExpressionInterpolatedStringHandler)`
- Modifiers: `static`
- Returns: [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L242)

Creates a new instance of [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) with the specified format and value providers.

```csharp
public class ReferenceExpression
{
    public static ReferenceExpression Create(
        in ExpressionInterpolatedStringHandler handler)
    {
        // ...
    }
}
```

## Parameters

- `handler` ([ExpressionInterpolatedStringHandler](/reference/api/csharp/aspire.hosting/expressioninterpolatedstringhandler.md))
  The handler that contains the format and value providers.

## Returns

[ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) -- A new instance of [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) with the specified format and value providers.

## CreateConditional(IValueProvider, string, ReferenceExpression, ReferenceExpression)

- Name: `CreateConditional(IValueProvider, string, ReferenceExpression, ReferenceExpression)`
- Modifiers: `static`
- Returns: [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L258)

Creates a conditional [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) that selects between two branch expressions based on the string value of a condition.

```csharp
public class ReferenceExpression
{
    public static ReferenceExpression CreateConditional(
        IValueProvider condition,
        string matchValue,
        ReferenceExpression whenTrue,
        ReferenceExpression whenFalse)
    {
        // ...
    }
}
```

## Parameters

- `condition` ([IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md))
  A value provider whose result is compared to `matchValue` to determine which branch to evaluate.
- `matchValue` (`string`)
  The string value that `condition` is compared against. When the condition's value equals this (case-insensitive), the `whenTrue` branch is selected.
- `whenTrue` ([ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md))
  The expression to evaluate when the condition matches `matchValue`.
- `whenFalse` ([ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md))
  The expression to evaluate when the condition does not match `matchValue`.

## Returns

[ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) -- A new conditional [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md).

## GetValueAsync(ValueProviderContext, CancellationToken)

- Name: `GetValueAsync(ValueProviderContext, CancellationToken)`
- Returns: `ValueTask<string?>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L227)

Gets the value of the expression. The final string value after evaluating the format string and its parameters.

```csharp
public class ReferenceExpression
{
    public ValueTask<string?> GetValueAsync(
        ValueProviderContext context,
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `context` ([ValueProviderContext](/reference/api/csharp/aspire.hosting/valueprovidercontext.md))
  A context for resolving the value.
- `cancellationToken` (`CancellationToken`)
  A `Threading.CancellationToken`.

## GetValueAsync(CancellationToken)

- Name: `GetValueAsync(CancellationToken)`
- Returns: `ValueTask<string?>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L227)

Gets the value of the expression. The final string value after evaluating the format string and its parameters.

```csharp
public class ReferenceExpression
{
    public ValueTask<string?> GetValueAsync(
        CancellationToken cancellationToken)
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`)
  A `Threading.CancellationToken`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
