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
Miscellaneous
Thread ID:
01474360
Message ID:
01474366
Views:
37
>Because they can hold any type.
>

May be you can convert both to string and then compare. Just a thought. Although it will not work, I think.

>>Why do you define them as public properties and of type object? Does Object implement IComparable interface? I doubt it, I think you need to use specific type for these properties.
>>
>>>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?
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform