出于好奇,有没有办法编写一个方法,例如:
public static MyType Parse(string stringRepresentation, [Internal] bool throwException = true)
{
// parsing logic here that conditionally throws an exception or returns null ...
}
public static MyType TryParse(string stringRepresentation)
{
return this.Parse(stringRepresentation, true);
}
我想在内部减少代码冗余,但仍然符合例如 (Try)Parse() 的 BCL 方法签名,但如果 c# 编译器在这种情况下可以生成第二个内部方法,那就太好了。
这已经以某种方式可能了吗?到目前为止找不到任何东西。