alielie
2025-03-13 a3ba25607612818c28d421bfa8eb2f92339d71ac
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
using System;
using System.Collections.Generic;
using System.Reflection;
 
namespace HMI.Util
{
    class PropertyHelper
    {
        public static List<PropertyInfo> GetAtterProperty<T, A>(out List<A> attrs) where A : Attribute
        {
            var result = new List<PropertyInfo>();
            attrs = new List<A>();
 
            var type = typeof(T);
            var attrType = typeof(A);
 
            PropertyInfo[] properties = type.GetProperties();
 
            foreach (var prop in properties)
            {
                if (Attribute.IsDefined(prop, attrType))
                {
                    result.Add(prop);
                    attrs.Add((A)Attribute.GetCustomAttribute(prop, attrType));
                }
            }
            return result;
        }
    }
}