使用 .Value 时,我不确定为什么会收到 'is a method, which is not valid in the given context'
When using .Value I'm not sure why I receive 'is a method, which is not valid in the given context'
在将字符串转换为数字时,我似乎无法使用 .Value。
我正在使用它来使用 Umbraco 构建响应式图像。
public static IHtmlString GetSrcSet(this IPublishedContent item, int width = 0, int height = 0, string widths = "300,600,768")
{
StringBuilder sb = new StringBuilder(string.Empty);
if (width == 0)
{
width = int.Parse(item.GetProperty("UmbracoWidth").ToString());
}
if (height == 0)
{
height = int.Parse(item.GetProperty("UmbracoHeight").ToString());
}
string[] splitWidths = widths.Split(',');
foreach (string newWidth in splitWidths)
{
. . .
}
return (new HtmlString(sb.ToString()));
}
我确信我需要在这些行上使用 .Value
if (width == 0)
{
width = int.Parse(item.GetProperty("UmbracoWidth").Value.ToString());
}
if (height == 0)
{
height = int.Parse(item.GetProperty("UmbracoHeight").Value.ToString());
}
但后来我得到
Error CS0119 'PublishedElementExtensions.Value(IPublishedElement, string, string, string, Fallback, object)' is a method, which is not valid in the given context
省略 .Value
:
Input string was not in a correct format.
您需要在值后添加括号。当您需要像方法一样调用它时,您当前正在像 属性 一样调用 Value。
if (width == 0)
{
width = int.Parse(item.GetProperty("UmbracoWidth").Value().ToString());
}
if (height == 0)
{
height = int.Parse(item.GetProperty("UmbracoHeight").Value().ToString());
}
在将字符串转换为数字时,我似乎无法使用 .Value。
我正在使用它来使用 Umbraco 构建响应式图像。
public static IHtmlString GetSrcSet(this IPublishedContent item, int width = 0, int height = 0, string widths = "300,600,768")
{
StringBuilder sb = new StringBuilder(string.Empty);
if (width == 0)
{
width = int.Parse(item.GetProperty("UmbracoWidth").ToString());
}
if (height == 0)
{
height = int.Parse(item.GetProperty("UmbracoHeight").ToString());
}
string[] splitWidths = widths.Split(',');
foreach (string newWidth in splitWidths)
{
. . .
}
return (new HtmlString(sb.ToString()));
}
我确信我需要在这些行上使用 .Value
if (width == 0)
{
width = int.Parse(item.GetProperty("UmbracoWidth").Value.ToString());
}
if (height == 0)
{
height = int.Parse(item.GetProperty("UmbracoHeight").Value.ToString());
}
但后来我得到
Error CS0119 'PublishedElementExtensions.Value(IPublishedElement, string, string, string, Fallback, object)' is a method, which is not valid in the given context
省略 .Value
:
Input string was not in a correct format.
您需要在值后添加括号。当您需要像方法一样调用它时,您当前正在像 属性 一样调用 Value。
if (width == 0)
{
width = int.Parse(item.GetProperty("UmbracoWidth").Value().ToString());
}
if (height == 0)
{
height = int.Parse(item.GetProperty("UmbracoHeight").Value().ToString());
}