学海无涯

导航

C# 智能枚举

public class PriorityStatus : SmartEnum<PriorityStatus>
{
  public static readonly PriorityStatus Backlog = new(nameof(Backlog), 0);
  public static readonly PriorityStatus Critical = new(nameof(Critical), 1);

  protected PriorityStatus(string name, int value) : base(name, value) { }
}

客户端使用:

  public ProjectStatus Status => _items.All(i => i.IsDone) ? ProjectStatus.Complete : ProjectStatus.InProgress;

 基础设施,数据库的实体配置类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using XFMES.Core.ApsAggregate;
using XFMES.Core.ProjectAggregate;

namespace XFMES.Infrastructure.Data.Config.Aps;
public class ShpFcNomarkDetailConfig : IEntityTypeConfiguration<ShpFcNomarkDetail>
{
  public void Configure(EntityTypeBuilder<ShpFcNomarkDetail> builder)
  {
    builder.Property(p => p.DepartmentCategories)
      .HasConversion(
          p => p.Value,
          p => DepartmentCategories.FromValue(p));
  }
}

  

 

 

posted on 2023-06-11 18:15  宁静致远.  阅读(67)  评论(0编辑  收藏  举报