Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating Value of unknown type at runtime
    primarykey
    data
    text
    <p>I found an nice code example for type validation:</p> <pre><code>public class StringViewModel : ViewModelBase, IComparable { private string _value; private string _originalValue; public StringViewModel(string value) { _value = value; _originalValue = value; } // Der eigentliche Wert. public string Value { get { return _value; } set { if (value != _value) { _value = value; RaisePropertyChanged("Value"); HasChanges = _value != _originalValue &amp;&amp; !(string.IsNullOrEmpty(_value) &amp;&amp; string.IsNullOrEmpty(_originalValue)); } } } public override void AcceptChanges() { _originalValue = _value; HasChanges = false; HasError = false; } public override void UndoChanges() { Value = _originalValue; HasError = false; } // Muss implementiert werden, damit die Sortierung im CollectionView funktioniert. public int CompareTo(object obj) { if (obj == null) return 1; if (object.ReferenceEquals(this, obj)) return 0; StringViewModel other = obj as StringViewModel; return string.Compare(this._value, other._value); } public override string ToString() { return _value; } } </code></pre> <p>Now I want do make it more generic, so I need to create the 2 values below at runtime:</p> <pre><code>private T? _value; private T? _originalValue; </code></pre> <p>because I want to do something like:</p> <pre><code>public class ItemModel : IComparable, INotifyEXTEND { private ??? _value; private ??? _originalValue; public ItemModel(string value) { _value = value; _originalValue = value; } public ??? Value { get { return _value; } set { if (value != _value) { _value = value; RaisePropertyChanged("Value"); HasChanges = _value != _originalValue &amp;&amp; !(string.IsNullOrEmpty(_value) &amp;&amp; string.IsNullOrEmpty(_originalValue)); } } } public override void AcceptChanges() { _originalValue = _value; HasChanges = false; HasError = false; } public override void UndoChanges() { Value = _originalValue; HasError = false; } public int CompareTo(object obj) { if (obj == null) return 1; if (object.ReferenceEquals(this, obj)) return 0; ??? other = obj as ???; return string.Compare(this._value, other._value); } public override string ToString() { return _value; } } </code></pre> <p>So I can use it like this:</p> <pre><code>public class PersonViewModel : ViewModelBase { private Person _person; private ItemModel _lastname; private ItemModel _birthdate; private bool _isNew; // Otherstuff } </code></pre> <p>Any suggestions on how to do this? (Some example code snippets or links would be nice)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload