Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:59:13+00:00 2026-06-13T11:59:13+00:00

I found an nice code example for type validation: public class StringViewModel : ViewModelBase,

  • 0

I found an nice code example for type validation:

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 && !(string.IsNullOrEmpty(_value) && 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;
    }
}

Now I want do make it more generic, so I need to create the 2 values below at runtime:

private T? _value;
private T? _originalValue;

because I want to do something like:

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 && !(string.IsNullOrEmpty(_value) && 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;
    }
}

So I can use it like this:

public class PersonViewModel : ViewModelBase
{

    private Person _person;
    private ItemModel _lastname;
    private ItemModel _birthdate;
    private bool _isNew;

    // Otherstuff
}

Any suggestions on how to do this? (Some example code snippets or links would be nice)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:59:14+00:00Added an answer on June 13, 2026 at 11:59 am

    You need to use generics:

    public class ItemModel<T> : IComparable<ItemModel<T>>, INotifyEXTEND where T : IComparable<T>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By using Google I have found some nice snippets of example code for using
I found a nice bit of code to add some 'normal' text links (i.e.
Found a really nice code for Accordion nav and am trying implement on our
I am looking for nice (java) code generation engine. I have found cglib but
I found some code like this in a project I'm working on public SqlDataReader
The Java - WebDriverBackedSelenium exporter I found generates code like this: selenium.open(/); selenium.type(Password, blah);
I found a nice script to import xml using powershell http://slash4.de/tutorials/Automatic_mediawiki_page_import_powershell_script Currently I don't
Well I found a nice tutorial about how to program applications using Bonjour. It's
I just found a nice tutorial that will help me implement an easy user
Using XSL 1.0, I found a nice tokenize function. Now I need to for-each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.