chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
    {
        ///// <summary>
        ///// 判断属性是否只读
        ///// </summary>
        ///// <param name="property">要检查的属性</param>
        ///// <param name="considerInitOnlyAsReadOnly">是否将init-only属性视为只读</param>
        ///// <param name="considerNonPublicSetterAsReadOnly">是否将非公共setter视为只读</param>
        ///// <returns>true如果属性是只读的</returns>
        //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<ReadOnlyAttribute>()?.IsReadOnly == true ||
        //           property.GetCustomAttribute<System.ComponentModel.ReadOnlyAttribute>()?.IsReadOnly == true;
        //}
    }
}