简体   繁体   English

C#IsNull()和IsEqualTo() - Visual Studio在示例Dapper.net / Contrib代码中无法识别它们

[英]C# IsNull() and IsEqualTo() - Visual Studio doesn't recognise them in sample Dapper.net / Contrib code

I'm sure I'm being really stupid here - but I'm getting into Dapper and contrib. 我敢肯定我在这里真的很蠢 - 但我正在进入Dapper和contrib。 Sample code includes lines like this: 示例代码包含以下行:

 using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
        {
            connection.Get<User>(3).IsNull();

            var id = connection.Insert(new User { Name = "Adam", Age = 10 });

IsNull() is never recognised. IsNull()永远不会被识别。 Nor is IsEqualTo in the same context. IsEqualTo也不在同一个上下文中。

I have googled - nothing close, searched in object browsers - am using Dapper - and using Dapper.Contrib.Extensions; 我用Google搜索 - 没有关闭,在对象浏览器中搜索 - 使用Dapper - 并使用Dapper.Contrib.Extensions; But it sill can't find it. 但它无法找到它。

thx 谢谢

Those are actually methods from the testing framework that is being used. 这些实际上是来自正在使用的测试框架的方法。 They are actually assertions; 它们实际上是断言; the IsNull() is asserting that the value on the left is null , and throwing an exception otherwise. IsNull() 断言左边的值为null ,否则抛出异常。 The IsEqualTo is asserting that the value on the left is equal to the value passed to the method, and throwing an exception otherwise. IsEqualTo 断言左边的值等于传递给方法的值,否则抛出异常。

You don't need those methods for real code. 您不需要那些方法来实际代码。 I guess that the example has been lifted from a test method, where it is being used to confirm the state of the data before and after the insert. 我猜这个例子已经从测试方法中解除了,它用于确认插入前后数据的状态。

It comes to mind that AssertNull and AssertEqualTo might be better names! 我想到AssertNullAssertEqualTo可能是更好的名字!

The code is in Assert.cs ; 代码在Assert.cs ; they could also be invoked via: 它们可以通过调用:

Assert.IsNull(connection.Get<User>(3));
...
Assert.IsEqualTo(someObj.SomeProp, 42);

etc, in which case the intent would be more obvious. 等等,在这种情况下,意图会更加明显。 The fact that they are extension methods hides a little bit of detail in this case (specifically, the fact that the declaring type is Assert ). 在这种情况下,它们是扩展方法的事实隐藏了一些细节(具体地说,声明类型是Assert的事实)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM