c# - C#:有没有办法让 T 更短的通用约束?
问题描述
我有一个方法看起来像:
void Do<T>(T arg) where T: IDisposeable, ICloneable, IRunnable, IMyInterface1;
为了使通用约束更短,我尝试使用新界面
interface ICombinedInterface: IDisposeable, ICloneable, IRunnable, IMyInterface1 {}
void Do<T>(T arg) where T: ICombinedInterface;
但是,一些第三方库没有也不会实现我的接口,所以我不能在我的Do<T>(T arg)
方法中使用他们的类。
反正有没有使通用约束更短?
解决方案
推荐阅读
- java - 滑动手势材料设计
- javascript - 更改表格中的行高
- google-apps-script - 带有公式值的 Google 表格 appendRow
- python - 不确定应该将哪个实例传递给参数
- macos - 文件夹中所有文件的 Shell 命令(macOS)
- javascript - 当一个类出现在 ViewPort 中时 jQuery 隐藏
- multithreading - 在 C 中生成具有相同参数的 n 个 pthread 的最有效方法
- python - 在 pandas 数据框列中展开嵌套的字典列表
- delphi - Delphi OmniThreadLibrary 和异步
- gcc - 这个 gcc 生成的 strlen() mips 循环如何不是一个接一个?