Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Codeproject,

I have a class called UIControl, and I've also made derived class like UIControlButton, UIControlImageBox. I've stored all of these in a List<uicontrol>.

Is there any way to check if any changes have been made to the objects in the List that isn't just Added or Removed an object?

I really want to make sure there's no cleaner way to check if any changes have been made than to compare all properties each time they're set in each individual class.

So in a nutshell, how do I figure out if an object's properties have changed by not using the object.Equal method since that would compare whether or not an object is in the same memory location -- and also using a method that would not require a dirty method like checking all properties for each method directly within the object itself.

Best Regards,
- Eds.

What I have tried:

I've tried doing a dirty method by just comparing one list to another list, one containing the objects whilst not changed, and one that could possibly changed, comparing those objects and in case they're different setting the old item to the new item and trigger an event like so:

public bool IsIdentical(UIControl Control, UIControl Other)
{
    if(Control.GetType() != Other.GetType())
    {
        return false;
    }

    if(!Control.Name.Equals(Other.Name))
    {
        return false;
    }

    return false;
}


The problem however is that some derived controls have other or multiple values, and I don't think it's a great idea to make 100s of overloads for each different control.
Posted
Updated 6-Feb-17 3:20am
v2
Comments
#realJSOP 6-Feb-17 9:14am    
Are you using WPF? And BTW, "Control" is a terrible name for a variable. Use "ctrl", or something like that.
Member 11841791 6-Feb-17 9:15am    
Very specifically I'm using Monogame (alternative to XNA.) I'm working on a UI engine and I need to register when changes have been made to the controls in order to make the drawing more efficient in panels. An example to changes would be the size of a control, the text in a control, the colors, and forward.

 
Share this answer
 
Comments
Member 11841791 6-Feb-17 9:13am    
Now this is more like it. Is there really no other way without having to raise the event in each property? If there isn't then that's no problem, I'll just work with that.
Peter Leow 6-Feb-17 9:15am    
Go for it.
Member 11841791 6-Feb-17 9:16am    
I'll give it a shot. Cheers Peter!
Karthik_Mahalingam 6-Feb-17 10:54am    
5! exactly.
Most of the time, there's an event you can handle that is control type-specific. Text boxes in Windows have TextChanged events, list boxes have SelectionChanged, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900