Beispiel #1
0
        public ObjectControl()
        {
            converterChanges
            .CombineLatest(objectChanges, comparerChanges, textBlockChanges, filterChanges, (valueConverter, value, comparer, textBlock, filter) => (valueConverter, value, comparer, textBlock, filter))
            .Subscribe(valueTuple =>
            {
                var(valueConverter, value, comparer, textBlock, filter) = valueTuple;

                Task.Run(() =>
                         value switch
                {
                    string _ => (Visibility.Collapsed, value),
                    Version _ => (Visibility.Collapsed, value),
                    { } x when x.GetType().IsClass == false => (Visibility.Collapsed, value),
                    null => (Visibility.Collapsed, value),
                    IEnumerable <string> _ => (Visibility.Collapsed, value),
                    IEnumerable enumerable when enumerable.NotOfClassType() => (Visibility.Collapsed, enumerable),
                    IEnumerable enumerable when enumerable.OfSameType() => (Visibility.Collapsed, enumerable),
                    IEnumerable enumerable => DictionaryConverter.ConvertMany(enumerable, valueConverter, filter, comparer)
                    .Pipe(a => (a.Keys.Cast <object>().Any() ? Visibility.Visible : Visibility.Collapsed, a)),
                    _ => DictionaryConverter.Convert(value, valueConverter, filter, comparer)
                    .Pipe(a => (a.Keys.Cast <object>().Any() ? Visibility.Visible : Visibility.Collapsed, a))
                })
                .ToObservable()
                .ObserveOnDispatcher()
                .Subscribe(a =>
                {
                    var(visibility, content) = a;
                    textBlock.SetValue(VisibilityProperty, visibility);
                    this.SetValue(ContentProperty, content);
                }, e =>
                {
                    SetValue(ContentProperty, new OrderedDictionary(1)
                    {
                        { "Error", e.Message }
                    });
                    this.Log().Write(e, $"Error in {nameof(ObjectControl)} creating content", typeof(ObjectControl), LogLevel.Error);
                },
                           () => { });
            });