toddams/RazorLight

让RazorLight支持DateTime等System中的基础方法

SharkLock opened this issue · 2 comments

#387 这个问题我也遇到了, 不过我用的是DateTime的对象同样提示

Failed to compile generated Razor template:
(3:17) The name 'DateTime' does not exist in the current context
See CompilationErrors for detailed information

Describe the solution you'd like
在这个文件中
D:\RazorLight\src\RazorLight\Generation\RazorSourceGenerator.cs
在internal protected RazorSourceDocument GetNamespacesImports()增加对Namespaces的非空判断
在public virtual async Task<IEnumerable> GetImportsAsync(RazorLightProjectItem projectItem)
中调整 TextSourceRazorProjectItem的返回值 变更后的代码如 下面两张图
image
image

代码变更后,目前已有的单元测试能正常通过
附支持后的单元测试, 如下图
image

@SharkLock
you may want to translate your message to English for better comprehension of everyone on Github.
We could all everyone open the translator, or you could do it once, thus you will help everyone once for all

Closing, as I have no idea what this is all about ¯_(ツ)_/¯