/// <summary> /// Retrieves all properties of a given <paramref name="targetType" /> which are inherting from /// <see cref="BaseDataModel" />. /// </summary> /// <param name="targetType">The type to inspect.</param> /// <returns>The list of properties deriving from <see cref="BaseDataModel" />.</returns> public static IEnumerable <PropertyInfo> GetPropertiesInheritingFromBaseDataModel(Type targetType) { if (BaseDataModelProperties.ContainsKey(targetType)) { // found it in the cache return(BaseDataModelProperties[targetType]); } // get all public non-static properties of the target type implementing IDataErrorInfo var result = targetType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => typeof(BaseDataModel).IsAssignableFrom(p.PropertyType)).Distinct().ToList(); // update the cache BaseDataModelProperties.TryAdd(targetType, result); // return result return(result); }
/// <inheritdoc /> protected override void OnPropertyChanged(string propertyName = null) { base.OnPropertyChanged(propertyName); // check if this property needs it's own validation if (PropertiesToValidate.Any(p => p.Name.Equals(propertyName))) { // this property should be validated ValidateProperty(propertyName); } if (IgnoreInternalModels) { // this view model should not handle internal BaseDataModels explicitely return; } // check if this property is of type BaseDataModel too var prop = BaseDataModelProperties.FirstOrDefault(p => p.Name.Equals(propertyName)); if (prop != null) { // this means there was a new instance assigned to this property AttachChildModelHandler(prop.GetValue(this) as BaseDataModel); } }