如何在Rider中实现接口时移除默认的Throw new System.NotImplementedException()行
在JetBrains Rider中修改接口实现的默认代码模板
- 打开Rider设置:使用快捷键
Ctrl+Alt+S(Windows/Linux)或Cmd+,(Mac),也可通过顶部菜单File → Settings(Windows/Linux)或Rider → Settings(Mac)进入设置界面。 - 定位到代码模板选项:在左侧导航栏依次展开 Editor → File and Code Templates,切换到Code标签页。
- 找到接口方法体模板:在右侧模板列表中找到Method body for interface method(部分版本可能显示为
Interface Method Body)。 - 修改模板内容:将默认的
throw new NotImplementedException();删除,替换为空白的大括号{ }(或你需要的其他默认内容)。 - 保存设置:点击界面底部的
Apply和OK按钮完成设置。
修改完成后,再实现接口时生成的方法就不会自动添加抛出异常的代码,示例如下:
public class CharacterA : MonoBehaviour, ICharacterController { public void UpdateRotation(ref Quaternion currentRotation, float deltaTime) { } }
内容的提问来源于stack exchange,提问作者KiynL
相关产品推荐
相关产品推荐

