Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Compare 2 Object Properties On A Class
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
How To Compare 2 Object Properties On A Class
Miscellaneous
Thread ID:
01474360
Message ID:
01474360
Views:
68
I have this class:
public class ReportColumn
{
    public string ColumnName { get; set; }
    public object OriginalValue { get; set; }
    public object ChangedValue { get; set; }
    public bool IsChanged { get; private set; }

    public void SetIsChanged()
    {
        IsChanged = false;

        PropertyInfo[] sourceProperties = OriginalValue.GetType().GetProperties();
        foreach (PropertyInfo pi in sourceProperties)
        {
            object originalProperty = OriginalValue.GetType().GetProperty(pi.Name).GetValue(this, null);
            object changedProperty = ChangedValue.GetType().GetProperty(pi.Name).GetValue(comparisonObject, null);

            IsChanged = (originalProperty != changedProperty);

            if (IsChanged)
            {
                break;
            }
        }
    }
}
I'm trying to set IsChanged, but the SetIsChanged method doesn't seem right. I want to compare the values of the OriginalValue and ChangedValue properties.

What's the right way to do this?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform