为 VS UT Assert 类创建自定义扩展方法的最佳方法是什么?

为 VS UT Assert 类创建自定义扩展方法的最佳方法是什么?

问题描述:

我想知道为 Microsoft Visual Studio 单元测试断言类编写自定义扩展方法的最佳方法是什么.

I would like to know what is the best way to write custom extensions methods for Microsoft Visual Studio Unit Testing Assert class.

如果您指的是这个 Assert 类,则不能添加扩展方法.扩展方法只能应用于对象实例.由于此类是静态的,因此永远无法实例化.

If you are referring to this Assert class, then you cannot add extension methods. Extension methods can only be applied to object instances. Since this class is static, it can never be instantiated.

您可以像这样添加自己的自定义断言类型类:

You could add your own custom Assert type class like so though:

public static class MyAssert {
    public static void AreEqual(object expected, object actual) {
        // TODO: throw if not equal
    }
}