为 VS UT Assert 类创建自定义扩展方法的最佳方法是什么? [英] What is the best way to create custom extension methods for VS UT Assert class?

查看:49
本文介绍了为 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
    }
}

这篇关于为 VS UT Assert 类创建自定义扩展方法的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆