using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace OpenTapEditor.Util { public static class PropertyInfoExtensions { ///// ///// 判断属性是否只读 ///// ///// 要检查的属性 ///// 是否将init-only属性视为只读 ///// 是否将非公共setter视为只读 ///// true如果属性是只读的 //public static bool IsReadOnly( // this PropertyInfo property, // bool considerInitOnlyAsReadOnly = true, // bool considerNonPublicSetterAsReadOnly = false) //{ // // 基本检查:没有setter就是只读 // if (property.SetMethod == null) // return true; // // 检查是否是init-only属性 // if (considerInitOnlyAsReadOnly && property.IsInitOnly()) // return true; // // 检查setter的可访问性 // if (considerNonPublicSetterAsReadOnly && !property.SetMethod.IsPublic) // return true; // // 检查是否有只读特性标记 // if (HasReadOnlyAttribute(property)) // return true; // return false; //} //private static bool HasReadOnlyAttribute(PropertyInfo property) //{ // return property.GetCustomAttribute()?.IsReadOnly == true || // property.GetCustomAttribute()?.IsReadOnly == true; //} } }