问题标签 [magic-string]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
165 浏览

c# - 需要字符串清单以避免 webapi c# 应用程序中的魔术字符串

我有 ac# webapi 应用程序,它到处都有魔术字符串和数字。我被要求通过一个字符串清单或一个将这些字符串保存在一个地方并引用它们的包来改变这一点。我不想使用枚举。我不知道什么是字符串清单或捆绑包。

有人可以通过一个例子给我一个关于如何做到这一点的想法。基本上,我需要避免在整个应用程序中进行硬编码,并为这些字符串使用外部配置,这样每当这些字符串值发生变化时,我们就不必编译和部署 .NET 应用程序。

想法是在某种包或字符串清单中显示所有预期的响应并引用它,而不是到处都有幻数和字符串。

我需要删除魔术案例编号和 FreeText,而是在一个地方配置这些值并引用它们,而无需再次部署应用程序。

0 投票
1 回答
70 浏览

python - 如何避免 python 中的 field_name 类中的魔术字符串,例如 c# 中的 nameof()

例如,在这个 python 代码中。

如何避免使用“名称”、“价格”作为字符串。有什么方法可以使用,比如

谢谢

0 投票
1 回答
79 浏览

jupyter-notebook - shell command # can't be carry out when it not used for comments on colab

I'm confused about this code! Why # cant't play a role that takes the length of a string?

In fact, the code behind # has become commented and cannot be executed!

Any advice?

0 投票
1 回答
445 浏览

commonjs - 汇总 commonJs 和 nodeResolve MagicString 错误

我想将 xml-js 库与汇总捆绑器一起使用。简单导入后出现错误,node_modules\xml-js\lib\index.js 未导出“json2xml”

我尝试使用最新版本的 commonjs rollup 插件修复它。尝试构建后,我得到了这个异常

rollup.config.js 看起来很简单

在空项目中安装相同的汇总插件后,我得到了同样的错误。你有什么建议吗?

0 投票
1 回答
48 浏览

entity-framework - .net 核心授权角色不使用魔术字符串

这是我的代码。但不工作

如果将 [Authorize(Roles = nameof(SD.ROLE_ADMIN))] 更改为 [Authorize(Roles = "admin")] 它可以正常工作

SD.ROLE_Admin -----> 公共静态字符串 ROLE_ADMIN {get; set;} = "admin" 在静态类

如何解决?谢谢你。