For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
预约演示登录免费开始
  • 使用 SDK
    • SDK 概述
    • SDK 如何工作
    • Quickstart
    • Customer showcase
  • 使用 SDK
    • 项目结构
    • 添加自定义代码
    • Migrating to Replay
    • 功能特性
  • 参考
      • Generating an SDK
      • 发布到 NuGet
      • Configuration
      • 添加自定义代码 (.NET)
      • .NET 兼容性
      • 变更日志
      • Customer showcase
  • 资源
    • generators.yml
Checking status...
SOC2Soc 2 Type II
© 2026 Fern • Birch Solutions, Inc., a Postman company

Documentation

SDKsDocsAsk FernCLI Reference

API Definitions

OpenAPIAsyncAPIOpenRPCgRPC

Resources

BlogSupportPricing

Company

Brand KitPrivacy PolicyTerms of Service
LogoLogo
预约演示登录免费开始
在本页
  • 添加自定义逻辑
  • 添加自定义 SDK 方法
参考.NET

添加自定义代码

||以 Markdown 格式查看|
此页面是否有帮助?
在仪表板中编辑
上一个

.NET 配置

下一个

.NET 兼容性

本页面介绍如何为你的 .NET SDK 添加自定义逻辑和方法。

These steps cover adding a new custom file to the SDK. To preserve line-level edits to a generated file, use Replay instead.

添加自定义逻辑

开始添加自定义代码:

1

创建一个新文件并添加你的自定义逻辑

src/YourNamespace/Helper.cs
1namespace YourNamespace;
2
3public static class Helper
4{
5 public static void MyHelper()
6 {
7 Console.WriteLine("Hello World!");
8 }
9}
2

将你的文件添加到 .fernignore

.fernignore
1# Specify files that shouldn't be modified by Fern
2
3src/YourNamespace/Helper.cs
3

使用辅助函数

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

1using YourNamespace;
2
3Helper.MyHelper();

添加自定义 SDK 方法

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.

1

更新 generators.yml 配置

将你的 Fern 生成的客户端命名为类似 BaseClient 的名称,以反映该客户端将被扩展。

generators.yml
1- name: fernapi/fern-csharp-sdk
2 version: 2.65.0
3 config:
4 client-class-name: BaseClient
2

导入并扩展生成的客户端

首先,导入 Fern 生成的基础客户端并扩展它。然后,添加你需要的任何方法。

src/YourNamespace/MyClient.cs
1namespace YourNamespace;
2
3public class MyClient : BaseClient
4{
5 public MyClient(ClientOptions? clientOptions = null) : base(clientOptions)
6 {
7 }
8
9 public void MyHelper()
10 {
11 Console.WriteLine("Hello World!");
12 }
13}
3

更新 .fernignore

将 MyClient.cs 添加到 .fernignore。

.fernignore
1+ src/YourNamespace/MyClient.cs
4

使用方法

用户将构造扩展的客户端,而不是生成的客户端。

1using YourNamespace;
2
3var client = new MyClient();

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

1client.MyHelper();