# ReferenceExpression

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs)
- Implements: [IExpressionValue](/reference/api/csharp/aspire.hosting/iexpressionvalue.md), [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md), [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md), [IValueWithReferences](/reference/api/csharp/aspire.hosting/ivaluewithreferences.md)

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.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public class ReferenceExpression
    : Aspire.Hosting.ApplicationModel.IExpressionValue,
      Aspire.Hosting.ApplicationModel.IManifestExpressionProvider,
      Aspire.Hosting.ApplicationModel.IValueProvider,
      Aspire.Hosting.ApplicationModel.IValueWithReferences
{
    // ...
}
```

## ATS metadata

### ATS export

- Type ID: `Aspire.Hosting/ReferenceExpression`

## Remarks

A [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) operates in one of two modes:

- Value mode -- a format string with interpolated [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) parameters (e.g., `"redis://{0}:{1}"`).
- Conditional mode -- a ternary-style expression that selects between two branch expressions based on the string value of a [ReferenceExpression.Condition](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#condition). Created via [ReferenceExpression.CreateConditional(IValueProvider, string, ReferenceExpression, ReferenceExpression)](/reference/api/csharp/aspire.hosting/referenceexpression/methods.md#createconditional-ivalueprovider-string-referenceexpression-referenceexpression).

## Properties

- [Condition](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#condition) : [IValueProvider?](/reference/api/csharp/aspire.hosting/ivalueprovider.md) `get` -- Gets the condition value provider whose result is compared to [ReferenceExpression.MatchValue](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#matchvalue), or `null` when [ReferenceExpression.IsConditional](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#isconditional) is `false`.
- [Format](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#format) : `string` `get` -- The format string for this expression.
- [IsConditional](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#isconditional) : `bool` `get` -- Gets a value indicating whether this expression is a conditional expression that selects between two branches based on a condition.
- [ManifestExpressions](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#manifestexpressions) : `IReadOnlyList<string>` `get` -- The manifest expressions for the parameters for the format string.
- [MatchValue](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#matchvalue) : `string?` `get` -- Gets the value that [ReferenceExpression.Condition](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#condition) is compared against to select the [ReferenceExpression.WhenTrue](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#whentrue) branch, or `null` when [ReferenceExpression.IsConditional](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#isconditional) is `false`.
- [StringFormats](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#stringformats) : `IReadOnlyList<string?>` `get` -- The string formats of the parameters, e.g. "uri".
- [ValueExpression](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#valueexpression) : `string` `get` -- The value expression for the format string.
- [ValueProviders](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#valueproviders) : [IReadOnlyList<IValueProvider>](/reference/api/csharp/aspire.hosting/ivalueprovider.md) `get` -- The list of [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) that will be used to resolve parameters for the format string.
- [WhenFalse](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#whenfalse) : [ReferenceExpression?](/reference/api/csharp/aspire.hosting/referenceexpression.md) `get` -- Gets the expression to evaluate when [ReferenceExpression.Condition](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#condition) does not evaluate to [ReferenceExpression.MatchValue](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#matchvalue), or `null` when [ReferenceExpression.IsConditional](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#isconditional) is `false`.
- [WhenTrue](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#whentrue) : [ReferenceExpression?](/reference/api/csharp/aspire.hosting/referenceexpression.md) `get` -- Gets the expression to evaluate when [ReferenceExpression.Condition](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#condition) evaluates to [ReferenceExpression.MatchValue](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#matchvalue), or `null` when [ReferenceExpression.IsConditional](/reference/api/csharp/aspire.hosting/referenceexpression/properties.md#isconditional) is `false`.

## Methods

- [Create(ExpressionInterpolatedStringHandler)](/reference/api/csharp/aspire.hosting/referenceexpression/methods.md#create-expressioninterpolatedstringhandler) : [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) `static` -- Creates a new instance of [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) with the specified format and value providers.
- [CreateConditional(IValueProvider, string, ReferenceExpression, ReferenceExpression)](/reference/api/csharp/aspire.hosting/referenceexpression/methods.md#createconditional-ivalueprovider-string-referenceexpression-referenceexpression) : [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) `static` -- 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.
- [GetValueAsync(ValueProviderContext, CancellationToken)](/reference/api/csharp/aspire.hosting/referenceexpression/methods.md#getvalueasync-valueprovidercontext-cancellationtoken) : `ValueTask<string?>` -- Gets the value of the expression. The final string value after evaluating the format string and its parameters.
- [GetValueAsync(CancellationToken)](/reference/api/csharp/aspire.hosting/referenceexpression/methods.md#getvalueasync-cancellationtoken) : `ValueTask<string?>` `ats export` -- Gets the value of the expression. The final string value after evaluating the format string and its parameters.

## Fields

- [Empty](/reference/api/csharp/aspire.hosting/referenceexpression/fields.md#empty) : [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) `static` -- Represents an empty reference expression with no name, value providers, or arguments.

## Nested Types

- [ExpressionInterpolatedStringHandler](/reference/api/csharp/aspire.hosting/expressioninterpolatedstringhandler.md) -- Represents a handler for interpolated strings that contain expressions. Those expressions will either be literal strings or instances of types that implement both [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) and [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md).
