小编Jon*_*zzi的帖子

在打字稿上扩展超级测试

我正在尝试在 supertest 上创建一个扩展。

使用我在问题Extending SuperTest 中发现的内容。我有这个工作示例javascript

const request = require('supertest');
const Test = request.Test;

Test.prototype.authenticate = function(user) {
  const {token, xsrfToken} = user.tokens;

  return this
   .set('Authorization', `Bearer ${token}`)
   .set('X-XSRF-TOKEN', xsrfToken);
}
Run Code Online (Sandbox Code Playgroud)

在测试块内,我可以使用:

request(app)
  .post('/user/settings')
  .authenticate(user)
  .send(...)
Run Code Online (Sandbox Code Playgroud)

这工作正常。现在的问题是在*.test.ts文件中使用扩展名。

正如使用 Typescript 扩展 Express Request 对象中所建议的那样,我尝试创建一个文件以使用typescript功能 Declaration Merging

// file location: ./src/types/supertest

declare namespace supertest {
  export interface Test {
    authenticate(user: any): this; // I didn't put a …
Run Code Online (Sandbox Code Playgroud)

testing bdd node.js typescript supertest

3
推荐指数
2
解决办法
3911
查看次数

从DataGridView获取DataTable,尊重过滤器和排序

我有一个System.Windows.Forms.DataGridView充满数据.我正在使用这样的代码:

System.Data.DataTable dataTable1;
System.Windows.Forms.BindingSource bindingSource1;
System.Windows.Forms.DataGridView dataGridView1;

// (...)

bindingSource1.DataSource = dataTable1;

dataGridView1.DataSource = bindingSource1;

bindingSource1.Filter = "Some Filter Here";
Run Code Online (Sandbox Code Playgroud)

我现在需要的是恢复其中的数据dataGridView1.但它不需要复杂.我的dataGridView1是readonly所以我唯一需要的是尊重订单和使用的过滤器,并将数据导出到DataTable.

有人可以帮帮我吗?

.net c# winforms

2
推荐指数
1
解决办法
2807
查看次数

动态构造Expression <Func <T,bool >>不适用于GreaterThen

嗨,我在Entity Framework中有一个简单的查询:

using (var db = new BookstoreContext())
{
    return db.Book
        .Where(w => w.PublishedYear > 2005)
        .ToList();
}
Run Code Online (Sandbox Code Playgroud)

现在我想将此查询更改为更动态的内容.但我想改变,不仅是常量值(2005),还有我的列字段(PublishedYear).

我正在寻找几天如何动态构建一个Expression<Func<,>>.现在我找到了这个页面,我正试图这样做.到目前为止,我来到这里:

public IEnumerable<Book> GetBooksGreaterThan(string columnName, object value)
{
    using (var db = new BookstoreContext())
    {
        return  db.Book
            .Where(GreaterThan(columnName, value))
            .ToList();
    }
}

public Expression<Func<Book, bool>> GreaterThan(string columnName, object value)
{
    var param = Expression.Parameter(typeof(Book), "w");
    var property = Expression.PropertyOrField(param, columnName);
    var body = Expression.GreaterThan(property, Expression.Constant(value));

    return Expression.Lambda<Func<Book, bool>>(body, param);
}
Run Code Online (Sandbox Code Playgroud)

但在第15行(var body …

c# expression entity-framework entity-framework-4

1
推荐指数
1
解决办法
1113
查看次数

C#6.0"string"和$"string"之间的性能差异

我在C#6.0中有2个代码:

样本1:

var foo = "Some text, " +
          $"some other {bar}, " +
          "end text.";
Run Code Online (Sandbox Code Playgroud)

样本2:

var foo = $"Some text, " +
          $"some other {bar}, " +
          $"end text.";
Run Code Online (Sandbox Code Playgroud)

显然两个代码都会产生相同的结果,但第二个代码在美学上更加美观(这是我的意见,请记住每个代码都有你的).

问题:
如果不需要$,是否有问题(性能或其他)写一个前缀为$的字符串.

编辑: 回答一些投诉:

第二个是可怕的.不要对未插值的字符串使用字符串插值符号($).任何看过代码的人(或未来,更有经验的人)都会感到困惑

这完全是您的看法,我在这里有一个团队,有10位高级C#开发人员,都同意第二个更清晰.

@ChetanRanpariya这不是真的.插值字符串是用于调用string.Format的语法糖,必须调用它(从而影响性能).

你需要提供证明你在说什么.

c# syntactic-sugar string-interpolation c#-6.0

-2
推荐指数
1
解决办法
547
查看次数