您可以在 Razor 中[废弃] DisplayTemplate 吗?
我在 Razor 中创建了一个专门用于显示货币的显示模板,现在我想在代码中将其删除并替换为接受字符串格式的标准文本显示模板(我可以将其设置为“C”)。
然而,这种情况有很多,所以我想使用类似 [Obsolete] 属性和警告消息的东西,以允许在接下来的几周内完成此操作,而不会破坏所有代码。
这是可能的还是有等效的方法?
干杯,
亚当。
I created a display template in Razor specifically for displaying currency, which I now want to remove in my code and replace with a standard text display template that accepts a string format (which I can set to "C").
There are a lot of occurrences however so I would like to use something like the [Obsolete] attribute with a warning message to allow this to be done over the course of the next couple of weeks without breaking all the code.
Is this possible or is there an equivalent method?
Cheers,
Adam.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎不是:(
DisplayTemplates 是通用的,例如:
要使用
[Obsolete]
,您必须标记 DisplayFor 方法,该方法适用于所有模板。我尝试创建一个“更具体的" 版本,看看它是否会选择它(因为您可以将其标记为[Obsolete]
,如下所示:遗憾的是,这不起作用 - 它会给出以下错误:
所以我认为您无法使用
[Obsolete]
实现您所需要的。如果您确实无法在 IDE 中选择对 DisplayFor 的调用,您可以尝试在模板内记录堆栈跟踪(因为您可以在其中执行任何 C#),然后运行应用程序。这不会是万无一失的,但可能会有所帮助。Seemingly not :(
The DisplayTemplates are generic, eg.:
To use
[Obsolete]
, you'd have to mark the DisplayFor method, which would apply to them all. I tried to create a "more specific" version, to see if it would pick that up (since you could then mark that as[Obsolete]
, like this:Sadly, this didn't work - it gives the following error:
So I don't think you can achieve what you need with
[Obsolete]
. If you really can't pick through the calls to DisplayFor in the IDE, you could try logging the stack trace inside the template (since you can execute any C# inside it) and then running through the app. This won't be bullet-proof, but might help a little.