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> cache = new ConcurrentDictionary>(); 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()?.Browsable ?? true) .OrderBy(x => x.GetAttribute()?.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 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() == null).ToArray(); var result = props.ToLookup(p => p.Name, p => p).ToDictionary(g => g.Key, g => g.Last()); cache[type] = result; return result; } } }