# ReferenceExpressionBuilder Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ReferenceExpressionBuilder](/reference/api/csharp/aspire.hosting/referenceexpressionbuilder.md)
- Kind: `Methods`
- Members: `9`

A builder for creating [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md) instances.

## Append(ReferenceExpressionBuilderInterpolatedStringHandler)

- Name: `Append(ReferenceExpressionBuilderInterpolatedStringHandler)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L503)

Appends an interpolated string to the expression.

```csharp
public class ReferenceExpressionBuilder
{
    public void Append(
        in ReferenceExpressionBuilderInterpolatedStringHandler handler)
    {
        // ...
    }
}
```

## Parameters

- `handler` ([ReferenceExpressionBuilderInterpolatedStringHandler](/reference/api/csharp/aspire.hosting/referenceexpressionbuilderinterpolatedstringhandler.md))

## AppendFormatted(string?)

- Name: `AppendFormatted(string?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L521-L522)

Appends a formatted value to the expression.

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendFormatted(
        string? value)
    {
        // ...
    }
}
```

## Parameters

- `value` (`string?`)
  The formatted string to be appended to the interpolated string.

## AppendFormatted(string?, string?)

- Name: `AppendFormatted(string?, string?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L532-L541)

Appends a formatted value to the expression.

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendFormatted(
        string? value,
        string? format = null)
    {
        // ...
    }
}
```

## Parameters

- `value` (`string?`)
  The formatted string to be appended to the interpolated string.
- `format` (`string?`) `optional`
  The format to be applied to the value. e.g., "uri"

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AppendFormatted(T)

- Name: `AppendFormatted(T)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L550-L551)

Appends a formatted value to the expression. The value must implement [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) and [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md).

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendFormatted<T>(
        T valueProvider)
    {
        // ...
    }
}
```

## Parameters

- `valueProvider` (`T`)
  An instance of an object which implements [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) and [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md).

## Exceptions

- `InvalidOperationException`

## AppendFormatted(ReferenceExpression, string)

> **Obsolete:** ReferenceExpression instances can't be used in interpolated string with a custom format. Duplicate the inner expression in-place.

- Name: `AppendFormatted(ReferenceExpression, string)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs)

Appends the formatted value provided by the specified reference expression to the output.

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendFormatted(
        ReferenceExpression valueProvider,
        string format)
    {
        // ...
    }
}
```

## Parameters

- `valueProvider` ([ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md))
  A reference expression that supplies the value to be formatted and appended.
- `format` (`string`)
  A composite format string that specifies how the value should be formatted, or null to use the default format.

## Remarks

This method is marked obsolete only to prevent usages of this type explicitly.

## AppendFormatted(T, string?)

- Name: `AppendFormatted(T, string?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs)

Appends a formatted value to the expression. The value must implement [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) and [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md).

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendFormatted<T>(
        T valueProvider,
        string? format)
    {
        // ...
    }
}
```

## Parameters

- `valueProvider` (`T`)
  An instance of an object which implements [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) and [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md).
- `format` (`string?`)
  The format to be applied to the value. e.g., "uri"

## Exceptions

- `InvalidOperationException`

## AppendLiteral(string)

- Name: `AppendLiteral(string)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L512-L513)

Appends a literal value to the expression.

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendLiteral(
        string value)
    {
        // ...
    }
}
```

## Parameters

- `value` (`string`)
  The literal string value to be appended to the interpolated string.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AppendValueProvider(object, string?)

- Name: `AppendValueProvider(object, string?)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs#L593-L610)

Appends a value provider to the expression using late binding. The object must implement both [IValueProvider](/reference/api/csharp/aspire.hosting/ivalueprovider.md) and [IManifestExpressionProvider](/reference/api/csharp/aspire.hosting/imanifestexpressionprovider.md), or be an `ApplicationModel.IResourceBuilder`1` where T implements both interfaces.

```csharp
public class ReferenceExpressionBuilder
{
    public void AppendValueProvider(
        object valueProvider,
        string? format = null)
    {
        // ...
    }
}
```

## Parameters

- `valueProvider` (`object`)
  An object that implements both interfaces, or an IResourceBuilder wrapping such an object.
- `format` (`string?`) `optional`
  Optional format specifier.

## Exceptions

- `ArgumentException` -- Thrown if the object doesn't implement the required interfaces.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## Build

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

Builds the [ReferenceExpression](/reference/api/csharp/aspire.hosting/referenceexpression.md).

```csharp
public class ReferenceExpressionBuilder
{
    public ReferenceExpression Build()
    {
        // ...
    }
}
```

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
