在我们的项目中,我们在几个地方使用System.Web.Mvc.MvcHtmlString。在添加了对ServiceStack程序集的引用之后,我得到了编译错误:
Cannot convert expression type System.Web.Mvc.MvcHtmlString to return type MvcHtmlString
碰撞是System.Web.Mvc.MvcHtmlString与MvcHtmlString在ServiceStack中的碰撞。在ServiceStack中,这个类没有名称空间,您可以在下面的代码或github上看到
这有什么好的理由吗?这个类不应该在ServiceStack.Html命名空间中吗?命名空间已在最后一次提交中删除。
有很好的解决办法吗?我必须在所有出现的MvcHtmlString前加上名称空间前缀System.Web.Mvc。
using System;
using System.Diagnostics.CodeAnalysis;
using System.Web;
public sealed class MvcHtmlString : HtmlString
{
private readonly string _value;
public MvcHtmlString(string value)
: base(value ?? String.Empty)
{
_value = value ?? String.Empty;
}
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes", Justification = "MvcHtmlString is immutable")]
public static readonly MvcHtmlString Empty = Create(String.Empty);
public static MvcHtmlString Create(string value)
{
return new MvcHtmlString(value);
}
public static bool IsNullOrEmpty(MvcHtmlString value)
{
return (value == null || value._value.Length == 0);
}
}发布于 2014-10-16 00:14:59
该提交似乎被错误地还原到全局命名空间中。它已经被重构到ServiceStack.Html命名空间在这个承诺中中。
此更改可从v4.0.33+ (现在为可在MyGet上获得 )中获得。
https://stackoverflow.com/questions/26392192
复制相似问题