我试图编写一个尝试执行操作但吞下任何引发的异常的方法.
我的第一次尝试如下:
public static void SafeExecute(Action actionThatMayThrowException) {
try {
actionThatMayThrowException();
} catch {
// noop
}
}
Run Code Online (Sandbox Code Playgroud)
使用同步操作调用时有效:
SafeExecute(() => {
throw new Exception();
});
Run Code Online (Sandbox Code Playgroud)
但是在使用异步操作调用时失败:
SafeExecute(async () => {
await Task.FromResult(0);
throw new Exception();
});
Run Code Online (Sandbox Code Playgroud)
有可能编写一个处理这两种情况的方法吗?
.net c# exception-handling task-parallel-library async-await
构建C#8.0的文章指出
目前的计划是C#8.0将与.NET Core 3.0同时发布.但是,随着我们正在开发的Visual Studio 2019的预览,这些功能将开始活跃起来.
C#8.0,.NET Core 3.0和Visual Studio之间有什么关系?
作为后续,我也很困惑在物理部署方面新的语言版本实际上是什么.它是作为新的Visual Studio部署的一部分部署的新程序集,还是部分网络核心sdk安装或其他部分?是否需要将C#8添加到完整框架和.NET Core?
目前,对于每个GET,我必须从路由参数手动创建查询对象.
是否可以直接绑定到查询对象?
所以,而不是:
[Route("{id:int}")]
public Book Get(int id) {
var query = new GetBookByIdQuery {
Id = id
};
// execute query and return result
}
Run Code Online (Sandbox Code Playgroud)
我能做到这一点:
[Route("{id:int}")]
public Book Get(GetBookByIdQuery query) {
// execute query and return result
}
Run Code Online (Sandbox Code Playgroud)
其中GetBookByIdQuery的样子:
public class GetBookByIdQuery {
public int Id { get; set;}
}
Run Code Online (Sandbox Code Playgroud) 我的理解是,nuget CLI和visual studio本身不仅可以使用官方nuget.org提要,还可以使用来自第三方网站(如myget)的其他提要.
这是否意味着Feed本身遵循定义的标准,因此这些工具可以与任何Feed一起使用?
如果是这样我在哪里可以找到这个标准?
我也困惑的之间的区别v2和v3nuget.org饲料.
更新
我现在明白官方nuget feed有两个版本,v2它们是基于OData的,v3它是一个rest api.我也明白nuget cli和visual studio能够与两者交谈.
我仍然不明白的是,如果你看看这篇文章https://docs.nuget.org/create/hosting-your-own-nuget-feeds,它说明
有几个第三方NuGet服务器可以使远程私有源易于配置和设置,包括Visual Studio Team Services,MyGet,Inedo的ProGet,JFrog的Artifactory,NuGet Server和Sonatype的Nexus.请参阅NuGet生态系统概述以了解有关这些选项的更多信息.
对于nuget cli和visual studio都能够使用所有这些不同的第三方提要,肯定必须有一些潜在的通用标准提要格式.它们是否都使用相同的OData格式v2?这是我的问题的关键.
我们有一个传统的服务器渲染应用程序(非SPA),其中每个页面都增加了vuejs
现有的webpack 3配置是
webpack.config.js
var webpack = require('webpack')
var path = require('path')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = {
entry: {
shared: './shared.js',
pageA: './pageA.js',
// pageB: './pageB.js',
// pageC: './pageC.js',
// etc
},
resolve: {
alias: { vue: 'vue/dist/vue.esm.js' },
},
output: {
path: path.join(__dirname, './dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
query: {
sourceMap: true,
},
}, …Run Code Online (Sandbox Code Playgroud) 我有一个通用类型,它包装一个原始类型以赋予它值相等语义
public class ValueObject<T>
{
public T Value { get; }
public ValueObject(T value) => Value = value;
// various other equality members etc...
}
Run Code Online (Sandbox Code Playgroud)
它的用法如下:
public class CustomerId : ValueObject<Guid>
{
public CustomerId(Guid value) : base(value) { }
}
public class EmailAddress : ValueObject<string>
{
public EmailAddress(string value) : base(value) { }
}
Run Code Online (Sandbox Code Playgroud)
问题是在序列化类型时,例如:
public class Customer
{
public CustomerId Id { get; }
public EmailAddress Email { get; }
public Customer(CustomerId id, EmailAddress email)
{
Id = id; …Run Code Online (Sandbox Code Playgroud) 想象一下以下人为的例子:
public class LoginController {
private readonly IValidate _validator;
private readonly IAuthenticate _authenticator;
public LoginController(IValidate validator, IAuthenticate authenticator) {
_validator = validator;
_authenticator = authenticator;
}
public HttpStatusCode Login(LoginRequest request) {
if (!_validator.IsValid(request)) {
return HttpStatusCode.BadRequest;
}
if (!_authenticator.IsAuthenticated(request.Email, request.Password)) {
return HttpStatusCode.Unauthorized;
}
return HttpStatusCode.OK;
}
}
public class LoginRequest {
public string Email {get; set;}
public string Password {get; set;}
}
public interface IValidate {
bool IsValid(LoginRequest request);
}
public interface IAuthenticate {
bool IsAuthenticated(string email, string password); …Run Code Online (Sandbox Code Playgroud) 我试图使用jshint和npm脚本命令来lint我的所有javascript文件.
我在Windows上运行,无论我指定哪个通配符,我似乎都不能lint多个文件.
引用特定文件有效:
"scripts": {
"lint": "jshint app/main.js"
}
Run Code Online (Sandbox Code Playgroud)
但以下所有结果都会导致错误:
"scripts": {
// results in Can't open app/**/*.js'
"lint1": "jshint app/**/*.js",
// results in Can't open app/*.js'
"lint2": "jshint app/*.js",
// results in Can't open app/**.js'
"lint3": "jshint app/**.js",
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用webpack将我的供应商脚本与我的应用程序脚本分开捆绑.
index.js
var _ = require('lodash');
console.log(_)
Run Code Online (Sandbox Code Playgroud)
webpack.config.js
var path = require('path');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var config = {
entry: {
vendor: ['lodash'],
app: './index.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].[chunkhash].js'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: Infinity,
}),
new HtmlWebpackPlugin({
filename: 'index.html',
inject: true
})
]
};
module.exports = config;
Run Code Online (Sandbox Code Playgroud)
结果
Run Code Online (Sandbox Code Playgroud)Asset Size Chunks Chunk Names app.3437c5da57e0c6671675.js 145 bytes 0 [emitted] app vendor.72c95e21a8d7096d53bc.js 428 kB 1 [emitted] vendor …
Deconstruct给定一个具有如下方法的对象:
record Point(int X, int Y);
var point = new Point(1, 2);
var (x, y) = point;
Console.WriteLine(x); // 1
Console.WriteLine(y); // 2
Run Code Online (Sandbox Code Playgroud)
是否可以在 LINQ select 语句中解构对象的值?
例如而不是:
points.Select(p => p.X + p.Y)
Run Code Online (Sandbox Code Playgroud)
这
// CS0019 Operator '+' cannot be applied to operands of type 'UserQuery.Point' and 'int'
points.Select((x, y) => x + y)
Run Code Online (Sandbox Code Playgroud)
这会导致编译错误,因为它使用的Select方法重载需要Func<Point, int>
c# ×5
.net ×1
async-await ×1
bdd ×1
c#-8.0 ×1
javascript ×1
json.net ×1
node.js ×1
npm ×1
nuget ×1
tdd ×1
testing ×1
unit-testing ×1
webpack ×1
webpack-4 ×1