C#: Any way to suppress compiler errors similar to suppressing warning messages?

前端 未结 3 2056
有刺的猬
有刺的猬 2020-12-20 18:07

I have the following code that generates a compiler error:

    Boolean IConvertible.ToBoolean(IFormatProvider provider)
    {
        ThrowHelper.ThrowInvali         


        
3条回答
  •  萌比男神i
    2020-12-20 18:46

    You could have the method in ThrowHelper only create the exception, not actually throw it.

    Boolean IConvertible.ToBoolean(IFormatProvider provider)
    {
        throw ThrowHelper.CreateInvalidCast(typeof(MyType), typeof(Boolean));
    }
    

    This would probably result in a better stack trace as well: it would point at ToBoolean, not at ThrowInvalidCast.

提交回复
热议问题