Files
SzmediTools/Szmedi.RevitToolkit.Approval/Assists/IOAssists.cs

38 lines
1.3 KiB
C#
Raw Normal View History

2025-09-16 16:06:41 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Szmedi.RevitToolkit.Approval.Models;
namespace Szmedi.RevitToolkit.Approval.Assists
{
internal class IOAssists
{
public static string GetMvdLiteContent(string majorName)
{
var dir = Path.Combine(GlobalAssists.DirAssembly, "mvdlite");
var fileContent = Directory.GetFiles(dir, "*.mvdlite")
.FirstOrDefault(f => f.Contains(majorName)) switch
{
string file when !string.IsNullOrEmpty(file) => File.ReadAllText(file),
_ => throw new FileNotFoundException("未找到对应的MVDLite文件请检查目录或文件名。")
};
return fileContent;
}
public static string GetMvdLiteContent(Major major)
{
var fieldInfo = major.GetType().GetField(major.ToString());
DescriptionAttribute descriptionAttribute = fieldInfo.GetCustomAttribute<DescriptionAttribute>();
var majorName = descriptionAttribute.Description;
return GetMvdLiteContent(majorName);
}
}
}