小编Vic*_*sov的帖子

C# 8 中 System.Type 的 Switch 表达式

我很好奇是否还有其他方法可以在 C# 8 中使用新的 switch 表达式编写类似的内容?

public static object Convert(string str, Type type) =>
    type switch
    {
        _ when type == typeof(string) => str,
        _ when type == typeof(string[]) => str.Split(new[] { ',', ';' }),
        _ => TypeDescriptor.GetConverter(type).ConvertFromString(str)
    };
Run Code Online (Sandbox Code Playgroud)

因为_ when type == typeof(string)看起来有点奇怪,尤其是当我们有打字模式和其他非常方便的工具时。

c# switch-statement c#-8.0

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

未捕获的类型错误:__webpack_require__(...).context 不是函数

当我尝试使用以下代码动态导入 vue 组件时:

const components = require.context('./', true, '/^index\.js$/');
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

app.js:9 Uncaught TypeError: __webpack_require__(...).context is not a function
    at Module../asset/app.js (app.js:9)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Object.0 (app.293d5fe1d8a073fed37a.bundle.js:1747)
    at __webpack_require__ (bootstrap:782)
    at checkDeferredModules (bootstrap:45)
    at bootstrap:858
    at bootstrap:858
Run Code Online (Sandbox Code Playgroud)

这是为什么?如何解决?我错过了什么?

webpack webpack-4

7
推荐指数
3
解决办法
7441
查看次数

标签 统计

c# ×1

c#-8.0 ×1

switch-statement ×1

webpack ×1

webpack-4 ×1