public static DependencyProperty Attach <TValue>( // public static DependencyProperty<TValue> Attach<TValue>( Type owner, [NotNull] Meta <DependencyObject, TValue> meta, [CanBeNull] PropertyValidate <TValue> validation = null, [NotNull, CallerMemberName] string autoFieldName = "") { meta.IsNotNull(nameof(meta)); autoFieldName.IsNotNull(nameof(autoFieldName)); return(DependencyProperty.RegisterAttached( GetPropertyName(autoFieldName), typeof(TValue), owner, meta, validation.TryInvoke)); }
public static DependencyPropertyKey RegisterReadOnly <TOwner, TValue>( [NotNull] Meta <TOwner, TValue> meta, [CanBeNull] PropertyValidate <TValue> validation = null, [NotNull, CallerMemberName] string autoFieldName = "") where TOwner : DependencyObject { meta.IsNotNull(nameof(meta)); autoFieldName.IsNotNull(nameof(autoFieldName)); return(DependencyProperty.RegisterReadOnly( GetReadOnlyPropertyName(autoFieldName), typeof(TValue), typeof(TOwner), meta, validation.TryInvoke)); }
private void CreateInnerFilter(PropertyValidate propertyInfo, KvP property) { var filter = new PropertiesFilter(propertyInfo.PropertyType); switch (new FilterEditor(filter).ShowDialog()) { case DialogResult.OK: property.Value = filter; bsFilters.ResetCurrentItem(); break; case DialogResult.Cancel: break; case DialogResult.Abort: property.Value = null; bsFilters.ResetCurrentItem(); break; } }
private void CreateDateTimeFilter(PropertyValidate propertyInfo, KvP property) { Func <DateTime, bool> Between(DateTime from, DateTime to) => src => from <= src && src <= to; var intervalPicker = new IntervalPicker(); switch (intervalPicker.ShowDialog()) { case DialogResult.OK: property.Value = Between(intervalPicker.From, intervalPicker.To); bsFilters.ResetCurrentItem(); break; case DialogResult.Cancel: break; case DialogResult.Abort: property.Value = null; bsFilters.ResetCurrentItem(); break; } }
public static bool TryInvoke <TValue>( this PropertyValidate <TValue> @this, object _value) { if (@this == null) { return(true); } if (_value == null) { return(false); } if (!(_value is TValue)) { throw new InvalidCastException( $"The \'baseValue\' argument must be of type \'{typeof(TValue).Name}\'."); } var value = (TValue)_value; return(@this.Invoke(value)); }
public static bool TryInvoke <T>(this PropertyValidate <T> i, object value) { return(i == null || i.Invoke((T)value)); }
bool IsInnerFilteredType(PropertyValidate propertyInfo) => (!propertyInfo.PropertyType.IsPrimitive || DigitalTypes.Contains(propertyInfo.PropertyType)) && propertyInfo.PropertyType != typeof(string) && propertyInfo.SourceList == null;
public static DependencyProperty Attach <D, T>(Meta <DependencyObject, T> meta, PropertyValidate <T> validation = null, [CallerMemberName] string autoFieldName = null) => DependencyProperty.RegisterAttached(GetPropertyName(autoFieldName), typeof(T), typeof(D), new FrameworkPropertyMetadata(meta.DefaultValue, meta.Flags, meta.ChangedCallback.TryInvoke, meta.CoerceCallback.TryInvoke), validation.TryInvoke);
public static DependencyProperty Attach <T>(Type owner, FrameworkPropertyMetadata meta, PropertyValidate <T> validation = null, [CallerMemberName] string autoFieldName = null) => DependencyProperty.RegisterAttached(GetPropertyName(autoFieldName), typeof(T), owner, meta, validation.TryInvoke);