C# 将代码从Umbraco v7复制到Umbraco v8时出现问题

C# 将代码从Umbraco v7复制到Umbraco v8时出现问题,c#,umbraco7,umbraco8,C#,Umbraco7,Umbraco8,我正试图将一些代码从一个在Umbraco v7上构建的站点复制到一个在Umbraco v8上构建的站点,但是一些类在新版本中似乎不存在。这是我试图复制的类: using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Web; using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; usi

我正试图将一些代码从一个在Umbraco v7上构建的站点复制到一个在Umbraco v8上构建的站点,但是一些类在新版本中似乎不存在。这是我试图复制的类:

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"); }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq.Expressions;
使用System.Web;
使用Umbraco.Core.Models;
使用Umbraco.Core.Models.PublishedContent;
使用Umbraco.Web;
使用Umbraco.ModelsBuilder;
使用Umbraco.ModelsBuilder.Umbraco;
命名空间XXXX.UmbracoStarterKit.CMS.Models
{
//混入别名为“baseImage”的内容类型1245
///基本图像
公共部分接口IBaseImage:IPPublishedContent
{
///备选案文
字符串ImageAlt{get;}
///字节
字符串UmbracoBytes{get;}
///延伸
字符串扩展名{get;}
///高度
字符串{get;}
///宽度
字符串宽度{get;}
}
///基本图像
[PublishedContentModel(“baseImage”)]
公共部分类BaseImage:PublishedContentModel,IBaseImage
{
#pragma warning disable 0109//new是冗余的
公共新常量字符串ModelTypeAlias=“baseImage”;
public new const PublishedItemType ModelItemType=PublishedItemType.Media;
#pragma警告恢复0109
公共基础映像(IPPublishedContent内容)
:基本(内容)
{ }
#pragma warning disable 0109//new是冗余的
公共新静态发布的内容类型GetModelContentType()
{
返回PublishedContentType.Get(ModelItemType,ModelTypeAlias);
}
#pragma警告恢复0109
公共静态PublishedPropertyType GetModelPropertyType(表达式选择器)
{
返回PublishedContentModelity.GetModelPropertyType(GetModelContentType(),选择器);
}
///
///替代文本:当图像无法显示时使用的文本。这对搜索引擎优化和可访问性非常有用。
///
[ImplementPropertyType(“imageAlt”)]
公共字符串ImageAlt
{
获取{return GetImageAlt(this);}
}
///替代文本的静态getter
公共静态字符串GetImageAlt(IBaseImage that){返回该.GetPropertyValue(“imageAlt”);}
///
///字节:图像的大小(以字节为单位)。
///
[ImplementPropertyType(“umbracoBytes”)]
公共字符串字节数
{
获取{return GetUmbracoBytes(this);}
}
///字节的静态getter
公共静态字符串getumbracopytes(IBaseImage that){返回该.GetPropertyValue(“umbracopytes”);}
///
///扩展名:图像扩展名。
///
[实现属性类型(“umbraco扩展”)]
公共字符串扩展名
{
获取{return GetUmbracoExtension(this);}
}
///用于扩展的静态getter
公共静态字符串GetUmbracoExtension(IBaseImage that){返回该.GetPropertyValue(“umbracoExtension”);}
///
///高度:图像的高度。
///
[实现属性类型(“umbracoHeight”)]
公共字符串高度
{
获取{return GetUmbracoHeight(this);}
}
///静态高度吸气剂
公共静态字符串GetUmbracoHeight(IBaseImage that){返回该.GetPropertyValue(“umbracoHeight”);}
///
///宽度:图像的宽度。
///
[实现属性类型(“umbracoWidth”)]
公共字符串宽度
{
获取{return GetUmbracoWidth(this);}
}
///宽度静态吸气剂
公共静态字符串GetUmbracoWidth(IBaseImage that){返回该.GetPropertyValue(“umbracoWidth”);}
}
}
上面有一个属性(
PublishedContentModel(“BaseImage”)
),但在v8中似乎不存在。在v7中,当我查看定义时,会看到PublishedContentModelAttribute,它是Umbraco.Core.Models.PublishedContent命名空间的一部分。v8中是否有替代品

在GetModelContentType方法中调用了PublishedContentType.Get,但v8中Umbraco.Core.Models.PublishedContent命名空间中也缺少Get方法。有什么建议可以替代吗

在GetModelPropertyType方法中,调用了PublishedContentModelity.GetModelPropertyType,但PublishedContentModelity在Umbraco.ModelBuilder.Umbraco中似乎不再存在。v8中是否有其他选择

此外,还有几个对that.GetPropertyValue的调用,它应该位于Umbraco.Web.PublishedContentTextenions命名空间中,但在v8中找不到。有人能建议我可以使用什么代码吗

我意识到这里有几个问题,但它们都是同一个问题的一部分,都妨碍我完成任务。

看一看


从v7到v8有很多变化,包括一些ModelsBuilder的东西。看起来其中一些正在使用接口。也许可以让Umbraco 8 ModelsBuilder为您创建一个全新的模型类,然后看看您是否可以通过这种方式发现更改?

谢谢您的帮助。我让一位同事教我如何使用ModelsBuilder,这就成功了