将代码从 Umbraco v7 复制到 Umbraco v8 时出现问题
Problems duplicating code from Umbraco v7 to Umbraco v8
我正在尝试将一些代码从基于 Umbraco v7 构建的站点复制到基于 Umbraco v8 构建的站点,但某些 classes 似乎不存在于新版本中。这是我要复制的 class:
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.ModelsBuilder;
using Umbraco.ModelsBuilder.Umbraco;
namespace XXXX.UmbracoStarterKit.CMS.Models
{
// Mixin content Type 1245 with alias "baseImage"
/// <summary>Base Image</summary>
public partial interface IBaseImage : IPublishedContent
{
/// <summary>Alternative Text</summary>
string ImageAlt { get; }
/// <summary>Bytes</summary>
string UmbracoBytes { get; }
/// <summary>Extension</summary>
string UmbracoExtension { get; }
/// <summary>Height</summary>
string UmbracoHeight { get; }
/// <summary>Width</summary>
string UmbracoWidth { get; }
}
/// <summary>Base Image</summary>
[PublishedContentModel("baseImage")]
public partial class BaseImage : PublishedContentModel, IBaseImage
{
#pragma warning disable 0109 // new is redundant
public new const string ModelTypeAlias = "baseImage";
public new const PublishedItemType ModelItemType = PublishedItemType.Media;
#pragma warning restore 0109
public BaseImage(IPublishedContent content)
: base(content)
{ }
#pragma warning disable 0109 // new is redundant
public new static PublishedContentType GetModelContentType()
{
return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
}
#pragma warning restore 0109
public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<BaseImage, TValue>> selector)
{
return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
}
///<summary>
/// Alternative Text: The text used if the image cannot be displayed. This can be useful for SEO and accessibility.
///</summary>
[ImplementPropertyType("imageAlt")]
public string ImageAlt
{
get { return GetImageAlt(this); }
}
/// <summary>Static getter for Alternative Text</summary>
public static string GetImageAlt(IBaseImage that) { return that.GetPropertyValue<string>("imageAlt"); }
///<summary>
/// Bytes: The size of the image in bytes.
///</summary>
[ImplementPropertyType("umbracoBytes")]
public string UmbracoBytes
{
get { return GetUmbracoBytes(this); }
}
/// <summary>Static getter for Bytes</summary>
public static string GetUmbracoBytes(IBaseImage that) { return that.GetPropertyValue<string>("umbracoBytes"); }
///<summary>
/// Extension: The image extension.
///</summary>
[ImplementPropertyType("umbracoExtension")]
public string UmbracoExtension
{
get { return GetUmbracoExtension(this); }
}
/// <summary>Static getter for Extension</summary>
public static string GetUmbracoExtension(IBaseImage that) { return that.GetPropertyValue<string>("umbracoExtension"); }
///<summary>
/// Height: The height of the image.
///</summary>
[ImplementPropertyType("umbracoHeight")]
public string UmbracoHeight
{
get { return GetUmbracoHeight(this); }
}
/// <summary>Static getter for Height</summary>
public static string GetUmbracoHeight(IBaseImage that) { return that.GetPropertyValue<string>("umbracoHeight"); }
///<summary>
/// Width: The width of the image.
///</summary>
[ImplementPropertyType("umbracoWidth")]
public string UmbracoWidth
{
get { return GetUmbracoWidth(this); }
}
/// <summary>Static getter for Width</summary>
public static string GetUmbracoWidth(IBaseImage that) { return that.GetPropertyValue<string>("umbracoWidth"); }
}
}
在public partial class BaseImage
上面有一个属性(PublishedContentModel("baseImage")
),但是v8中好像没有这个。在 v7 中,当我查看定义时,我看到了 PublishedContentModelAttribute,它是 Umbraco.Core.Models.PublishedContent 命名空间的一部分。 v8 中是否有替代品?
在 GetModelContentType 方法中有对 PublishedContentType.Get 的调用,但 v8 中的 Umbraco.Core.Models.PublishedContent 命名空间也缺少 Get 方法。有什么建议可以代替吗?
在 GetModelPropertyType 方法中调用了 PublishedContentModelUtility.GetModelPropertyType,但 PublishedContentModelUtility 似乎不再存在于 Umbraco.ModelBuilder.Umbraco 中。 v8 有替代方案吗?
此外,还有几个对that.GetPropertyValue的调用,应该在Umbraco.Web.PublishedContentExtenions命名空间中,但在v8中找不到。谁能建议我可以改用什么代码?
我知道这里有几个问题,但它们都是同一个问题的一部分,都在阻止我完成我的任务。
看看https://our.umbraco.com/forum/umbraco-8/98400-errors-thrown-after-upgrade-to-811
从 v7 到 v8 发生了很多变化,包括一些 ModelsBuilder 内容。看起来其中一些现在正在使用接口。也许让 Umbraco 8 ModelsBuilder 为您创建一个全新的模型 class 然后看看您是否可以通过这种方式发现变化?
我正在尝试将一些代码从基于 Umbraco v7 构建的站点复制到基于 Umbraco v8 构建的站点,但某些 classes 似乎不存在于新版本中。这是我要复制的 class:
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.ModelsBuilder;
using Umbraco.ModelsBuilder.Umbraco;
namespace XXXX.UmbracoStarterKit.CMS.Models
{
// Mixin content Type 1245 with alias "baseImage"
/// <summary>Base Image</summary>
public partial interface IBaseImage : IPublishedContent
{
/// <summary>Alternative Text</summary>
string ImageAlt { get; }
/// <summary>Bytes</summary>
string UmbracoBytes { get; }
/// <summary>Extension</summary>
string UmbracoExtension { get; }
/// <summary>Height</summary>
string UmbracoHeight { get; }
/// <summary>Width</summary>
string UmbracoWidth { get; }
}
/// <summary>Base Image</summary>
[PublishedContentModel("baseImage")]
public partial class BaseImage : PublishedContentModel, IBaseImage
{
#pragma warning disable 0109 // new is redundant
public new const string ModelTypeAlias = "baseImage";
public new const PublishedItemType ModelItemType = PublishedItemType.Media;
#pragma warning restore 0109
public BaseImage(IPublishedContent content)
: base(content)
{ }
#pragma warning disable 0109 // new is redundant
public new static PublishedContentType GetModelContentType()
{
return PublishedContentType.Get(ModelItemType, ModelTypeAlias);
}
#pragma warning restore 0109
public static PublishedPropertyType GetModelPropertyType<TValue>(Expression<Func<BaseImage, TValue>> selector)
{
return PublishedContentModelUtility.GetModelPropertyType(GetModelContentType(), selector);
}
///<summary>
/// Alternative Text: The text used if the image cannot be displayed. This can be useful for SEO and accessibility.
///</summary>
[ImplementPropertyType("imageAlt")]
public string ImageAlt
{
get { return GetImageAlt(this); }
}
/// <summary>Static getter for Alternative Text</summary>
public static string GetImageAlt(IBaseImage that) { return that.GetPropertyValue<string>("imageAlt"); }
///<summary>
/// Bytes: The size of the image in bytes.
///</summary>
[ImplementPropertyType("umbracoBytes")]
public string UmbracoBytes
{
get { return GetUmbracoBytes(this); }
}
/// <summary>Static getter for Bytes</summary>
public static string GetUmbracoBytes(IBaseImage that) { return that.GetPropertyValue<string>("umbracoBytes"); }
///<summary>
/// Extension: The image extension.
///</summary>
[ImplementPropertyType("umbracoExtension")]
public string UmbracoExtension
{
get { return GetUmbracoExtension(this); }
}
/// <summary>Static getter for Extension</summary>
public static string GetUmbracoExtension(IBaseImage that) { return that.GetPropertyValue<string>("umbracoExtension"); }
///<summary>
/// Height: The height of the image.
///</summary>
[ImplementPropertyType("umbracoHeight")]
public string UmbracoHeight
{
get { return GetUmbracoHeight(this); }
}
/// <summary>Static getter for Height</summary>
public static string GetUmbracoHeight(IBaseImage that) { return that.GetPropertyValue<string>("umbracoHeight"); }
///<summary>
/// Width: The width of the image.
///</summary>
[ImplementPropertyType("umbracoWidth")]
public string UmbracoWidth
{
get { return GetUmbracoWidth(this); }
}
/// <summary>Static getter for Width</summary>
public static string GetUmbracoWidth(IBaseImage that) { return that.GetPropertyValue<string>("umbracoWidth"); }
}
}
在public partial class BaseImage
上面有一个属性(PublishedContentModel("baseImage")
),但是v8中好像没有这个。在 v7 中,当我查看定义时,我看到了 PublishedContentModelAttribute,它是 Umbraco.Core.Models.PublishedContent 命名空间的一部分。 v8 中是否有替代品?
在 GetModelContentType 方法中有对 PublishedContentType.Get 的调用,但 v8 中的 Umbraco.Core.Models.PublishedContent 命名空间也缺少 Get 方法。有什么建议可以代替吗?
在 GetModelPropertyType 方法中调用了 PublishedContentModelUtility.GetModelPropertyType,但 PublishedContentModelUtility 似乎不再存在于 Umbraco.ModelBuilder.Umbraco 中。 v8 有替代方案吗?
此外,还有几个对that.GetPropertyValue的调用,应该在Umbraco.Web.PublishedContentExtenions命名空间中,但在v8中找不到。谁能建议我可以改用什么代码?
我知道这里有几个问题,但它们都是同一个问题的一部分,都在阻止我完成我的任务。
看看https://our.umbraco.com/forum/umbraco-8/98400-errors-thrown-after-upgrade-to-811
从 v7 到 v8 发生了很多变化,包括一些 ModelsBuilder 内容。看起来其中一些现在正在使用接口。也许让 Umbraco 8 ModelsBuilder 为您创建一个全新的模型 class 然后看看您是否可以通过这种方式发现变化?