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 8670197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:39:22+00:00 2026-06-12T18:39:22+00:00

I have a base class for a BLL that includes the following function: public

  • 0

I have a base class for a BLL that includes the following function:

    public bool IsDirty { get; protected set; }

    internal void SetField<TParam>(ref TParam field, TParam value)
    {
        if (EqualityComparer<TParam>.Default.Equals(field, value) == false)
        {
            field = value;
            IsDirty = true;
        }
    }

In the classes that inherit the base class I use this as a wrapper around the SET object, such as:

    public string UserName
    {
        get { return _userName; }
        set { SetField(ref _userName, value); }
    }

I use the IsDirty property to test to see if I need to issue an Update. If at least one of the properties changes then save to database. This works for most types but Collections and Lists can change without using set. I wrote a wrapper for the Collection to have an IsDirty flag on the List which could be tested for change:

    public class CollectionChangeTracked<T> : Collection<T>
    {
        public bool IsDirty {get; set;}

        public CollectionChangeTracked()
        {
            IsDirty = false;
        }

        protected override void InsertItem(int index, T newItem)
        {
            base.InsertItem(index, newItem);
            IsDirty = true; 
        }

        protected override void SetItem(int index, T newItem)
        {
            base.SetItem(index, newItem);
            IsDirty = true;
        }

        protected override void RemoveItem(int index)
        {
            base.RemoveItem(index);
            IsDirty = true;
        }

        protected override void ClearItems()
        {
            base.ClearItems();
            IsDirty = true;
        }
    }
}

The problem is that I now have to test both the Classe’s IsDirty property and any CollectionChangeTracked.IsDirty flags for updates. I could create method that performs the test in one spot such as:

    public CollectionChangeTracked<ApplicationRole> RolesList
    {
        get { return _rolesList; }
        set { SetField(ref _rolesList, value); }
    }

    public override bool IsDirty
    {
        get { return ResolveIsDirty(); }
        protected set { _isDirty = value; }

    private bool ResolveIsDirty()
    { 
        bool returnValue;

        if (_isDirty || RolesList.IsDirty)
            returnValue = true;
        else
            returnValue = false;

        return returnValue;
    }

But it seems like I should be able to come up with a cleaner solution that would allow a Class that contains the Collection to subscribe to a change of IsDirty of the CollectionChangeTracked object and update the IsDirty based on that change. Is this the better approach and how would I implement?

  • 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-12T18:39:23+00:00Added an answer on June 12, 2026 at 6:39 pm

    you can use an ObservableCollection<T> register to the CollectionChanged event and mark the IsDirty flag when the event is raised.

    ...
    
    ObservableCollection<int> myCollection = new ObservableCollection<int>();
    myCollection.CollectionChanged += OnCollectionChanged;
    
    ...
    
    public void OnCollectionChanged( Object sender, NotifyCollectionChangedEventArgs e )
    {
       IsDirty = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class that looks like the following: template<typename T> class Base
I have a base class with the following (trimmed for brevity) declaration: public abstract
I have a base class ActivityA that has some dialogs: public static final int
I have a base class Foo that has an Update() function, which I want
I have a base class that looks like this: public abstract class MyBaseClass {
I have a base class with the following: public class BodyBase : UserControl {
I have a base class: class motorcycle { public: virtual int speed() { return
I have a base class ( car ) and a class that inherit the
I have a base class like this: public class BaseResponse { public string ErrorMessage
I have a base class with many sub-classes, and a generic function to cache

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.