using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; namespace Szmedi.RevitToolkit.Approval.Assists { internal class PropertyAssists { private static Dictionary> _defaults; // 默认初始值:程序目录下的 PropertyDefaults.json private static string _filePath = Path.Combine(GlobalAssists.DirAssembly, "PropertyDefaults.json"); public static void Load(string filePath = null) { if (!string.IsNullOrEmpty(filePath)) _filePath = filePath; if (!File.Exists(_filePath)) { _defaults = new Dictionary>(); var emptyJson = JsonConvert.SerializeObject(_defaults, Formatting.Indented); File.WriteAllText(_filePath, emptyJson); return; } var json = File.ReadAllText(_filePath); _defaults = JsonConvert.DeserializeObject>>(json); } public static string GetDefaultValue(string definitionName, string propName) { if (_defaults == null) return null; if (_defaults.TryGetValue(definitionName, out var props)) { if (props.TryGetValue(propName, out var value)) return value; } return null; } // 新增:设置属性默认值 public static void SetDefaultValue(string definitionName, string propName, string value) { if (_defaults == null) _defaults = new Dictionary>(); if (!_defaults.TryGetValue(definitionName, out var props)) { props = new Dictionary(); _defaults[definitionName] = props; } props[propName] = value; } // 新增:保存到文件 public static void Save() { if (string.IsNullOrEmpty(_filePath) || _defaults == null) return; var json = JsonConvert.SerializeObject(_defaults, Formatting.Indented); File.WriteAllText(_filePath, json); } } }