> This page is for SDKs, version Legacy.
> For other versions, use one of these documentation indexes:
> - Current (default): https://buildwithfern.com/learn/sdks/current/llms.txt
> - Legacy: https://buildwithfern.com/learn/sdks/legacy/llms.txt

> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# Adding custom code

> Add custom logic and methods to your .NET SDK with Fern. Extend BaseClient, create custom helpers, and use .fernignore effectively.

> **You're viewing the legacy SDK docs**
>
> These pages cover SDK generation configured with `generators.yml`. New projects use `sdk-config.yml`, so see [the Current version of this page](/learn/sdks/generators/csharp/custom-code) for up-to-date guidance. To move an existing project, follow the [SDK Config migration guide](/learn/sdks/legacy/generators/migration-guides/sdk-config), which walks through `fern sdk migrate`, and review the [`sdk-config.yml` reference](/learn/sdks/reference/sdk-config).

> **Enterprise feature**
>
> This feature is available only for the [Enterprise plan](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).

This page covers how to add custom logic and methods to your .NET SDK.

## Adding custom logic

To get started adding custom code:

> **Note**
>
> These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use [Replay](/learn/sdks/legacy/overview/custom-code#replay) instead.

#### Create a new file and add your custom logic

**`src/YourNamespace/Helper.cs`**

```csharp title="src/YourNamespace/Helper.cs"
namespace YourNamespace;

public static class Helper
{
    public static void MyHelper()
    {
        Console.WriteLine("Hello World!");
    }
}
```

#### Add your file to \`.fernignore\`

**`.fernignore`**

```yaml {3} title=".fernignore"
# Specify files that shouldn't be modified by Fern

src/YourNamespace/Helper.cs
```

#### Consume the helper

Now your users can consume the helper function by importing it from the SDK.

```csharp
using YourNamespace;

Helper.MyHelper();
```

## Adding custom SDK methods

Fern also allows you to add custom methods to the SDK itself (e.g.
`client.my_method()` ) by inheriting the Fern generated client and then
extending it.

#### Update \`generators.yml\` configuration

Name your Fern-generated client something like `BaseClient` to reflect that this client will be extended.

**`generators.yml`**

```yaml {4} title="generators.yml"
- name: fern-csharp-sdk
  version: 2.92.3
  config:
    client-class-name: BaseClient
```

#### Import and extend the generated client

First, import the Fern generated base client and extend it. Then, add whatever methods you want.

**`src/YourNamespace/MyClient.cs`**

```csharp title="src/YourNamespace/MyClient.cs"
namespace YourNamespace;

public class MyClient : BaseClient
{
    public MyClient(ClientOptions? clientOptions = null) : base(clientOptions)
    {
    }

    public void MyHelper()
    {
        Console.WriteLine("Hello World!");
    }
}
```

#### Update \`.fernignore\`

Add the `MyClient.cs` to `.fernignore`.

**`.fernignore`**

```diff title=".fernignore"
+ src/YourNamespace/MyClient.cs
```

#### Consume the method

Instead of constructing the generated client, your users will want to construct the extended client.

```csharp
using YourNamespace;

var client = new MyClient();
```

Now your users can consume the helper function by importing it from the SDK.

```csharp
client.MyHelper();
```