alielie
2026-09-10 f3889f2d36c50cf99468594854def9b7ed069fb5
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
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Xml.Serialization;
 
namespace OpenTap.Addin.Reader
{
    public class PropertyInfoCache
    {
        private static readonly ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>> cache = new ConcurrentDictionary<Type, Dictionary<string, PropertyInfo>>();
 
        public static void Refresh(params Type[] addIns)
        {
            GetProps(typeof(TestVariable));
            GetProps(typeof(TestPlan));
 
            var types = TypeData.GetDerivedTypes(TypeData.FromType(typeof(ITestStep)))
               .Where(x => x.CanCreateInstance)
               .Where(x => x.GetAttribute<BrowsableAttribute>()?.Browsable ?? true)
               .OrderBy(x => x.GetAttribute<DisplayAttribute>()?.Order);
            foreach (var type in types)
            {
                var target = type.CreateInstance().GetType();
                GetProps(target);
            }
            foreach (var addin in addIns)
            {
                TypeData.GetDerivedTypes(TypeData.FromType(addin));
                GetProps(addin);
            }
        }
 
        public static Dictionary<string, PropertyInfo> GetProps(Type type)
        {
            if (cache.ContainsKey(type))
            {
                return cache[type];
            }
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .Where(p => p.SetMethod != null && p.GetCustomAttribute<XmlIgnoreAttribute>() == null).ToArray();
            var result = props.ToLookup(p => p.Name, p => p).ToDictionary(g => g.Key, g => g.Last());
            cache[type] = result;
            return result;
        }
    }
}