网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using Dpz.Core.EnumLibrary;
using Dpz.Core.Infrastructure;
using Dpz.Core.Public.Entity;

#nullable enable

namespace Dpz.Core.Public.ViewModel.DynamicPages;

public class VmDynamicPage : IMapFrom<DynamicPage>
{
    [Required]
    public string? Id { get; set; }

    [Required]
    public string? Content { get; set; }

    /// <summary>
    /// 脚本 地址
    /// </summary>
    [XmlIgnore]
    public SortedDictionary<int, string>? Scripts { get; set; }

    [XmlArray(ElementName = "Scripts")]
    [XmlArrayItem(ElementName = "Script")]
    [JsonIgnore]
    public KeyValueElement[] SerializableScripts =>
        Scripts?.Select(x => new KeyValueElement(x.Key, x.Value)).ToArray() ?? [];

    /// <summary>
    /// 样式 地址
    /// </summary>
    [XmlIgnore]
    public SortedDictionary<int, string>? Styles { get; set; }

    [XmlArray(ElementName = "Styles")]
    [XmlArrayItem(ElementName = "Style")]
    [JsonIgnore]
    public KeyValueElement[] SerializableStyles =>
        Styles?.Select(x => new KeyValueElement(x.Key, x.Value)).ToArray() ?? [];

    /// <summary>
    /// Content-Type
    /// </summary>
    public PageContentType ContentType { get; set; }

    /// <summary>
    /// content type
    /// </summary>
    public string ContentTypeStr => ContentType.ToString();

    public VmUserInfo? Creator { get; set; }

    public DateTime CreateTime { get; set; } = DateTime.Now;

    public DateTime LastUpdateTime { get; set; } = DateTime.Now;
}
⚠⚠    以下内容为AI分析的结果,请根据实际情况进行判断。

上述代码定义了一个名为 VmDynamicPage 的类,它是一个视图模型(ViewModel),用于表示动态页面的相关数据。这个类实现了 IMapFrom<DynamicPage> 接口,表明它可以从 DynamicPage 实体映射而来。以下是对代码中各个部分的详细解释:

属性

  1. Id:

    • 类型: string?
    • 说明: 页面唯一标识符,使用了 [Required] 特性,表示该属性是必填的。
  2. Content:

    • 类型: string?
    • 说明: 页面内容,使用了 [Required] 特性,表示该属性是必填的。
  3. Scripts:

    • 类型: SortedDictionary<int, string>?
    • 说明: 存储脚本地址的字典,键为整数,值为字符串。使用了 [XmlIgnore] 特性,表示在 XML 序列化时忽略该属性。
  4. SerializableScripts:

    • 类型: KeyValueElement[]
    • 说明: 该属性用于序列化 Scripts 字典,将其转换为 KeyValueElement 数组,以便在 XML 中表示。使用了 LINQ 的 Select 方法进行转换。
  5. Styles:

    • 类型: SortedDictionary<int, string>?
    • 说明: 存储样式地址的字典,键为整数,值为字符串。使用了 [XmlIgnore] 特性,表示在 XML 序列化时忽略该属性。
  6. SerializableStyles:

    • 类型: KeyValueElement[]
    • 说明: 该属性用于序列化 Styles 字典,将其转换为 KeyValueElement 数组,以便在 XML 中表示。
  7. ContentType:

    • 类型: PageContentType
    • 说明: 表示页面的内容类型,使用了一个枚举类型 PageContentType
  8. ContentTypeStr:

    • 类型: string
    • 说明: 返回 ContentType 的字符串表示,方便在需要字符串形式的地方使用。
  9. Creator:

    • 类型: VmUserInfo?
    • 说明: 表示创建者的信息,类型为 VmUserInfo,可以为 null。
  10. CreateTime:

    • 类型: DateTime
    • 说明: 页面创建时间,默认为当前时间。
  11. LastUpdateTime:

    • 类型: DateTime
    • 说明: 页面最后更新时间,默认为当前时间。

总结

VmDynamicPage 类的主要功能是封装动态页面的相关信息,以便在应用程序中使用。它提供了必要的属性来描述页面的内容、样式、脚本、创建者信息以及时间戳等。通过实现 IMapFrom<DynamicPage> 接口,该类可以方便地与 DynamicPage 实体进行数据映射,适用于 MVC 或 MVVM 架构中的数据传输和视图展示。

loading