Custom Equals() and CompareTo() implementations for ObjectModelReference and DataFormatReference

This commit is contained in:
Michael Becker 2014-12-18 10:06:54 -05:00
parent 2413e5826e
commit 25f43684ff
2 changed files with 54 additions and 2 deletions

View File

@ -5,7 +5,7 @@ using System.Text;
namespace UniversalEditor
{
public class DataFormatReference : ReferencedBy<DataFormat>
public class DataFormatReference : ReferencedBy<DataFormat>, IComparable<DataFormatReference>
{
public class DataFormatReferenceCollection
: System.Collections.ObjectModel.Collection<DataFormatReference>
@ -202,5 +202,31 @@ namespace UniversalEditor
if (_referencesByGUID.ContainsKey(guid)) return _referencesByGUID[guid];
return null;
}
public override bool Equals(object obj)
{
DataFormatReference omr = (obj as DataFormatReference);
if (omr == null) return false;
if (mvarID == Guid.Empty)
{
// do not compare ID
if (mvarTypeName == null) return false;
return mvarTypeName.Equals(omr.TypeName);
}
return mvarID.Equals(omr.ID);
}
public int CompareTo(DataFormatReference other)
{
if (mvarID == Guid.Empty)
{
// do not compare ID
if (mvarTypeName == null)
{
if (other.ID == Guid.Empty && other.TypeName == null) return 0;
return -1;
}
return mvarTypeName.CompareTo(other.TypeName);
}
return mvarID.CompareTo(other.ID);
}
}
}

View File

@ -5,7 +5,7 @@ using System.Text;
namespace UniversalEditor
{
public class ObjectModelReference : ReferencedBy<ObjectModel>
public class ObjectModelReference : ReferencedBy<ObjectModel>, IComparable<ObjectModelReference>
{
public class ObjectModelReferenceCollection
: System.Collections.ObjectModel.Collection<ObjectModelReference>
@ -244,5 +244,31 @@ namespace UniversalEditor
if (_referencesByGUID.ContainsKey(guid)) return _referencesByGUID[guid];
return null;
}
public override bool Equals(object obj)
{
ObjectModelReference omr = (obj as ObjectModelReference);
if (omr == null) return false;
if (mvarID == Guid.Empty)
{
// do not compare ID
if (mvarTypeName == null) return false;
return mvarTypeName.Equals(omr.TypeName);
}
return mvarID.Equals(omr.ID);
}
public int CompareTo(ObjectModelReference other)
{
if (mvarID == Guid.Empty)
{
// do not compare ID
if (mvarTypeName == null)
{
if (other.ID == Guid.Empty && other.TypeName == null) return 0;
return -1;
}
return mvarTypeName.CompareTo(other.TypeName);
}
return mvarID.CompareTo(other.ID);
}
}
}