Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Compare 2 Object Properties On A Class
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01474360
Message ID:
01474366
Vues:
36
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform