小编Sma*_*kid的帖子

如何首先在EF 4.3代码中映射受保护的属性

在EF 4.3文档中说:

默认情况下,使用Code First构建数据库不包括私有,受保护或内部属性.如果您在模型中手动包含这些属性,Code First将忽略这些成员上的任何数据注释.这个问题现已修复,Code First处理数据注释.

我的问题是如何首先使用代码包含受保护的属性,特别是使用流畅的API?

entity-framework code-first

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

在属性中使用类型参数以使用带有泛型类型参数的ProducesResponseType的解决方法?

我有一个通用的ASP.NET Core WebApi控制器,如:

public abstract class EntityController<TEntity> 
{
    public IActionResult Get(string id)
    {
        var entity = ... //load from database by id
        if (entity != null) 
            return new JsonResult(value, this.SerializerSettings()) {StatusCode  200};
        return NotFound();
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在Get()方法上应用以下属性:

[ProducesResponseType(typeof(TEntity), 200)] //this causes compilation error.
[ProducesResponseType(typeof(Object), 404)]
Run Code Online (Sandbox Code Playgroud)

目前,唯一的解决方法是覆盖派生控制器中的每个方法并在其中添加属性:

public class DerivedController ?EntityController<MyEntity>
{
    [ProducesResponseType(typeof(TEntity), (int) HttpStatusCode.OK)]
    [ProducesResponseType(typeof(Object), (int) HttpStatusCode.NotFound)]
    public IActionResult Get(string id)
    {
        return base.Get(id);
    }
}
Run Code Online (Sandbox Code Playgroud)

我非常不方便我应该覆盖每个控制器中的每个REST方法,只是为了使用TEntity属性中的具体类型.:-(

有没有更好的工作?

c# asp.net

8
推荐指数
2
解决办法
2137
查看次数

ESLint:未找到规则“jest/valid-describe”的定义。(开玩笑/有效描述)

将 eslint 升级到 8 后,每个测试模块都出现以下错误:

 error  Definition for rule 'jest/valid-describe' was not found  jest/valid-describe
Run Code Online (Sandbox Code Playgroud)

的一部分eslintrc.json

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "plugin:jest/recommended"
  ],
  "plugins": ["@typescript-eslint", "import", "jest"],
  "env": {
    "jest/globals": true
  },
  "parser": "@typescript-eslint/parser",
  // ...
}
Run Code Online (Sandbox Code Playgroud)

软件包版本是:

    "@types/jest": "^27.0.3",
    "@typescript-eslint/eslint-plugin": "^5.4.0",
    "@typescript-eslint/experimental-utils": "^4.28.4",
    "@typescript-eslint/parser": "^5.4.0",
    "eslint": "^8.3.0",
    "eslint-config-react-app": "^6.0.0",
    "eslint-plugin-flowtype": "^8.0.3",
    "eslint-plugin-import": "^2.25.3",
    "eslint-plugin-jest": "^25.3.0",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-react": "^7.24.0",
    "eslint-plugin-react-hooks": "^4.3.0",
    "eslint-plugin-testing-library": "^5.0.0",
    "jest": "^27.0.6",
    "ts-jest": "^27.0.4",
Run Code Online (Sandbox Code Playgroud)

有任何想法吗 ?

eslint jestjs

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

Webpack-dev-server 提供旧文件内容

我有一个非常简单的项目:

appdir +- app +- main.js +- build +- bundle.js +- index.html +- webpack.config.js

webpack.config.js:

var path=require("path");

module.exports = {
    entry: path.resolve(__dirname, "./app/main.js"),
    output: {
        path: path.resolve(__dirname, "build"),
        filename: "bundle.js"
    }
};
Run Code Online (Sandbox Code Playgroud)

我张家的后main.js,的WebPack-dev的服务器好像它检测到的变化,并进行重新打包的bundle.js,但浏览器仍然收到的旧内容main.js

我通过执行启动服务器 webpack-dev-server webpack.config.js

有任何想法吗?

webpack webpack-dev-server

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

有没有办法在 PNPM 中排除特定包裹的提升?

YARN 有一个nohoist选项可以防止提升特定的包。

PNPM 有同等的选择吗?

pnpm

6
推荐指数
2
解决办法
8101
查看次数

如何使用asp.net 5项目运行nunit测试,特别是使用ReSharper?

我正在开发一个针对dnx451的asp.net 5应用程序.

asp.net 5项目依赖于为nunit 2.x编写的单元测试库.因此,对我来说合理的选择是使用nunit来测试asp.net 5项目.

当我在ReSharper中运行单元测试时,ReSharper使用附加消息"System.IO.FileNotFoundException:无法加载文件或程序集xxx"说"测试未运行".

nunit 2.6.4和3.0.0-beta-2都会导致相同的错误.

任何人都成功运行针对dnx项目的nunit测试?

resharper nunit asp.net-core

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

VSCode断点不能在带有gulp-sourcemaps生成的源映射的typescript中工作

users.ts在子目录中有一个打字稿文件routes.

gulp代码gulpfile.js:

var tsProject = ts.createProject(tsConfigFile);
return tsProject.src()
    .pipe(sourcemaps.init())
    .pipe(ts(tsProject))
    .js
    .pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: ''})) 
    .pipe(gulp.dest('.'));
Run Code Online (Sandbox Code Playgroud)

生成的源映射gulp-sourcemaps不适用于VSCode:

{"version":3,"sources":["routes/users.ts"],"names":[], "mappings":"...","file":"routes/users.js","sourceRoot":""}
Run Code Online (Sandbox Code Playgroud)

在VSCode中正常生成的tsc源映射:

{"version":3,"file":"users.js","sourceRoot":"","sources":["users.ts"],"names":[], "mappings":"..."}
Run Code Online (Sandbox Code Playgroud)

并且VSCode断点与生成的源映射一起正常工作tsc.

那么如何配置gulp-typescript/gulp-sourcemaps生成相同的源图tsc

typescript gulp gulp-sourcemaps visual-studio-code

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

如何在WebStorm 2016.1中运行用typescript编写的单个mocha测试

我为使用typescript编写的测试设置了一个mocha"运行配置",并且"run"命令完美地执行.

但是当我选择通过单击"运行"窗口中的"运行..."弹出菜单来运行单个测试时,会发生语法错误.

在运行窗口中,WebStorm执行如下操作: /usr/local/bin/node /(...)/node_modules/mocha/bin/_mocha --ui bdd --reporter /Applications/(...)/mochaIntellijReporter.js /(...)/my-test.ts --grep "MyTest Basic test$"

似乎WebStorm将.ts文件而不是生成的.js文件传递给mocha,从而导致语法错误.

任何想法或解决方法?

webstorm

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

如何检测打字稿函数是否异步

我编写了一个函数来处理异步函数引发的异常,例如:

protected safeAsync(f : e.RequestHandler) : e.RequestHandler {
    /* how to detect if `f` is an async function here ?? */
    const binded = f.bind(this);
    return async function innerCall(req : e.Request, res : e.Response, next : Function) {
        try {
            return await binded(req, res, next);
        } catch (err) {
            log.debug(err);
            return next(err);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

该参数f应该是一个异步函数,例如

public async signupPost(req : e.Request, res : e.Response, next : Function) {/*...*/}
Run Code Online (Sandbox Code Playgroud)

我的问题是:

在 中safeAsync,有没有办法检测是否f是异步函数,以便我可以记录对 的意外调用safeAsync

typescript

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