public SubtypingProperty(Type baseType, PropertyFactory modelFactory, Type[] availableTypes) { AvailableTypes = availableTypes.Select(x => { var attr = x.GetCustomAttribute <PwSubtypeAttribute>(); return(new SubTypeInfo(x, attr.Name)); }).ToArray(); ValueType = baseType; SelectedType.Where(x => x != null) .Subscribe(x => { try { Model.Value = modelFactory.Create(x.Type, Title.Value); } catch (Exception e) { Debugger.Log(1, "Error", $"Error from SubtypingProperty:\n{e}\n"); OnErrorSubject.OnNext(e); } }); Value = Model.Where(x => x != null) .SelectMany(x => x.Value) .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe); Model.Where(x => x != null) .SelectMany(x => x.OnError) .Subscribe(x => OnErrorSubject.OnNext(x)); }
private void Initialize(Type type) { Value = new ReactiveProperty <object> { Value = Activator.CreateInstance(type) }; foreach (var property in Properties) { property.Value.Subscribe(x => { try { property.PropertyInfo.SetValue(Value.Value, x); } catch (ArgumentException) { var ex = new Exceptions.PwInvalidStructureException($"{property.Title.Value} プロパティに Set アクセサがありません。"); OnErrorSubject.OnNext(ex); } if (property is ReferenceByIntProperty refModel) { refModel.PropertyToBindBack?.SetValue(Value.Value, refModel.SelectedObject.Value); } ValueChangedSubject.OnNext(Unit.Default); }, ex => Debugger.Log(0, "Exception", ex.ToString())); } OnError = Observable.Merge(Properties.Select(x => x.OnError)) .Merge(OnErrorSubject); }
public BasicCollectionProperty(Type type, PropertyFactory modelFactory) { CollectionValue = new CollectionHolder(type, modelFactory); Value = CollectionValue.Value.Cast <object>().ToReactiveProperty(); CollectionValue.OnError.Subscribe(x => OnErrorSubject.OnNext(x)); Collection = CollectionValue.Collection.ToReadOnlyReactiveCollection(x => x.model); }
public ReferenceByIntCollectionProperty(ReferencableMasterInfo source, string idPropertyName, PropertyFactory factory) { Source = source; IdPropertyName = idPropertyName; CollectionValue = new CollectionHolder(typeof(int[]), factory); Value = CollectionValue.Value .Cast <object>() .ToReactiveProperty(); CollectionValue.OnError.Subscribe(x => OnErrorSubject.OnNext(x)); Collection = CollectionValue.Collection.ToReadOnlyReactiveCollection(x => x.model); }
public override string ToString() { try { return($"<{GetType()}: {Value}>"); } catch (Exception e) { OnErrorSubject.OnNext(e); return("<表示エラー>"); } }
public StructProperty(Type type, PropertyFactory modelFactory) { ValueType = type; if (!type.IsValueType) { throw new ArgumentException("type が構造体を表す Type クラスではありません。"); } StructureValue = new StructureHolder(type, modelFactory); Value = new ReactiveProperty <object>(StructureValue.Value.Value, ReactivePropertyMode.RaiseLatestValueOnSubscribe); StructureValue.ValueChanged.Subscribe(x => Value.Value = StructureValue.Value.Value); StructureValue.OnError.Subscribe(x => OnErrorSubject.OnNext(x)); }
public CollectionViewModel(TProperty property, ViewModelFactory factory) : base(property) { Collection = property.Collection.ToReadOnlyReactiveCollection(x => { IPropertyViewModel vm = null; try { vm = factory.Create(x); } catch (Exception e) { OnErrorSubject.OnNext(e); return(null); } vm.OnChanged.Subscribe(y => OnChangedSubject.OnNext(Unit.Default)); vm.OnError.Subscribe(e => OnErrorSubject.OnNext(e)); return(vm); }); FormatedString = Property.Count.Select(x => $"Count = {x}") .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe); AddCommand.Subscribe(x => { try { Property.AddNewElement(); } catch (Exception e) { OnErrorSubject.OnNext(e); } OnChangedSubject.OnNext(Unit.Default); }); RemoveCommand.Subscribe(x => { try { Property.RemoveElementAt(x); } catch (Exception e) { OnErrorSubject.OnNext(e); } OnChangedSubject.OnNext(Unit.Default); }); EditCommand.Subscribe(x => ShowDetailSubject.OnNext(this)); UpCommand.Subscribe(x => { Property.Move(x - 1, x); SelectedIndex.Value = x - 1; }); DownCommand.Subscribe(x => { Property.Move(x + 1, x); SelectedIndex.Value = x; }); DuplicateCommand.Subscribe(x => { Property.Duplicate(x, x + 1); }); }