如何从自定义模型活页夹中删除魔术弦?
我现在已经编写了几个自定义模型绑定程序,并且意识到我已经陷入了依赖魔术字符串的陷阱,例如:
if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey"))
{
paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue;
}
我希望能够使用表达式来强类型前缀名称,但不知道如何做,并会感谢一些帮助。
谢谢。
I've written a couple of custom model binders now, and have realised that I've fallen into the trap of relying on magic strings, e.g.:
if (bindingContext.ValueProvider.ContainsPrefix("PaymentKey"))
{
paymentKey = bindingContext.ValueProvider.GetValue("PaymentKey").AttemptedValue;
}
I'd like to be able to use an expression to strongly-type the prefix names, but can't figure out how, and would be grateful for some assistance.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是
bindingContext.ModelName
所以您的代码可能会变成:What you are looking for is
bindingContext.ModelName
so your code could become: