/// <summary> /// Gets the specified component type. /// </summary> /// <param name="componentType">Type of the component.</param> /// <param name="name">The name.</param> /// <returns></returns> public static PropertyAccessor GetProperty(Type componentType, string name) { AccessorList list = null; PropertyAccessor accessor = null; list = Get(componentType, string.IsNullOrEmpty(name)); if (list.ContainsKey(name)) { accessor = list[name] as PropertyAccessor; } else { lock (list._lock) { if (list.ContainsKey(name)) { accessor = list[name] as PropertyAccessor; } else { var property = componentType.GetProperty(name); if (property != null) { list.Add((accessor = new PropertyAccessor(componentType, property))); } } } } return(accessor); }
/// <summary> /// Gets the specified component type. /// </summary> /// <param name="componentType">Type of the component.</param> /// <param name="withSubType">if set to <c>true</c> [with sub type].</param> /// <returns></returns> public static AccessorList GetProperties(Type componentType, bool withSubType = false) { AccessorList list = null; if (_accessors.ContainsKey(componentType)) { list = _accessors[componentType]; } else { lock (_lock) { if (_accessors.ContainsKey(componentType)) { list = _accessors[componentType]; } else { list = new AccessorList(); foreach (PropertyInfo item in AccessorList.GetProperties(componentType)) { if (withSubType || item.DeclaringType == componentType && !list.ContainsKey(item.Name)) { list.Add(new PropertyAccessor(componentType, item)); } } _accessors.Add(componentType, list); } } } return(list); }