# IntOrStringYamlConverter Methods

- Package: [Aspire.Hosting.Kubernetes](/reference/api/csharp/aspire.hosting.kubernetes.md)
- Type: [IntOrStringYamlConverter](/reference/api/csharp/aspire.hosting.kubernetes/intorstringyamlconverter.md)
- Kind: `Methods`
- Members: `3`

Provides a custom YAML type converter that facilitates serialization and deserialization of objects of type [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md). This converter supports both integers and strings.

## Accepts(Type)

- Name: `Accepts(Type)`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Yaml/IntOrStringConverter.cs#L24)

Determines whether the given type is supported by this YAML type converter.

```csharp
public class IntOrStringYamlConverter
{
    public bool Accepts(
        Type type)
    {
        // ...
    }
}
```

## Parameters

- `type` (`Type`)
  The type to check for compatibility with the YAML converter.

## Returns

`bool` -- Returns true if the specified type is [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md), otherwise false.

## ReadYaml(IParser, Type, ObjectDeserializer)

- Name: `ReadYaml(IParser, Type, ObjectDeserializer)`
- Modifiers: `nullable`
- Returns: `object?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Yaml/IntOrStringConverter.cs#L37-L45)

Reads a YAML scalar from the parser and converts it into an instance of [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md).

```csharp
public class IntOrStringYamlConverter
{
    public object? ReadYaml(
        IParser parser,
        Type type,
        ObjectDeserializer rootDeserializer)
    {
        // ...
    }
}
```

## Parameters

- `parser` (`IParser`)
  The YAML parser to read the scalar value from.
- `type` (`Type`)
  The target type for deserialization, expected to be [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md).
- `rootDeserializer` (`ObjectDeserializer`)
  The root deserializer used for handling nested deserialization.

## Returns

`object?` -- Returns an instance of [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md) constructed from the parsed scalar value.

## Exceptions

- `InvalidOperationException` -- Thrown if the current YAML event is not a scalar.

## WriteYaml(IEmitter, object?, Type, ObjectSerializer)

- Name: `WriteYaml(IEmitter, object?, Type, ObjectSerializer)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Yaml/IntOrStringConverter.cs#L58-L72)

Writes the given object to the provided YAML emitter using the appropriate format.

```csharp
public class IntOrStringYamlConverter
{
    public void WriteYaml(
        IEmitter emitter,
        object? value,
        Type type,
        ObjectSerializer serializer)
    {
        // ...
    }
}
```

## Parameters

- `emitter` (`IEmitter`)
  The emitter used to write the YAML output.
- `value` (`object?`)
  The object to be serialized. Expected to be of type [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md).
- `type` (`Type`)
  The type of the object being serialized.
- `serializer` (`ObjectSerializer`)
  The serializer to be used for complex object serialization.

## Exceptions

- `InvalidOperationException` -- Thrown when the provided value is not of type [Int32OrStringV1](/reference/api/csharp/aspire.hosting.kubernetes/int32orstringv1.md).
