SDK
生成多种语言的客户端库
添加自定义代码
本页面介绍如何为你的 .NET SDK 添加自定义逻辑和方法。
开始添加自定义代码:
1namespace YourNamespace;23public static class Helper4{5 public static void MyHelper()6 {7 Console.WriteLine("Hello World!");8 }9}
将你的文件添加到 .fernignore
.fernignore
1# Specify files that shouldn't be modified by Fern23src/YourNamespace/Helper.cs
Now your users can consume the helper function by importing it from the SDK.
1using YourNamespace;23Helper.MyHelper();
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.
client.my_method()
更新 generators.yml 配置
generators.yml
将你的 Fern 生成的客户端命名为类似 BaseClient 的名称,以反映该客户端将被扩展。
BaseClient
1- name: fernapi/fern-csharp-sdk2 version: 2.65.03 config:4 client-class-name: BaseClient
首先,导入 Fern 生成的基础客户端并扩展它。然后,添加你需要的任何方法。
1namespace YourNamespace;23public class MyClient : BaseClient4{5 public MyClient(ClientOptions? clientOptions = null) : base(clientOptions)6 {7 }89 public void MyHelper()10 {11 Console.WriteLine("Hello World!");12 }13}
更新 .fernignore
将 MyClient.cs 添加到 .fernignore。
MyClient.cs
1+ src/YourNamespace/MyClient.cs
用户将构造扩展的客户端,而不是生成的客户端。
1using YourNamespace;23var client = new MyClient();
1client.MyHelper();