init
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTS.DASLib.Service
|
||||
{
|
||||
// Custom comparer for the IDASCommunication class.
|
||||
public class AnalogInputDASChannelComparer : IEqualityComparer<AnalogInputDASChannel>
|
||||
{
|
||||
// GainInfo are equal if their Gain is equal.
|
||||
public bool Equals(AnalogInputDASChannel x, AnalogInputDASChannel y)
|
||||
{
|
||||
// Check whether the compared objects reference the same data.
|
||||
if (ReferenceEquals(x, y))
|
||||
return true;
|
||||
|
||||
// Check whether any of the compared objects is null.
|
||||
if (x is null || y is null)
|
||||
return false;
|
||||
|
||||
if (x.OwningModule == null || y.OwningModule == null)
|
||||
return false;
|
||||
|
||||
if (x.OwningModule.OwningDAS == null || y.OwningModule.OwningDAS == null)
|
||||
return false;
|
||||
|
||||
if (string.IsNullOrEmpty(x.OwningModule.OwningDAS.SerialNumber) ||
|
||||
string.IsNullOrEmpty(y.OwningModule.OwningDAS.SerialNumber))
|
||||
return false;
|
||||
|
||||
// Check whether they are equal.
|
||||
return x.ModuleChannelNumber == y.ModuleChannelNumber &&
|
||||
x.OwningModule.ModuleArrayIndex == y.OwningModule.ModuleArrayIndex &&
|
||||
x.OwningModule.OwningDAS.SerialNumber == y.OwningModule.OwningDAS.SerialNumber &&
|
||||
x.AbsoluteDisplayOrder == y.AbsoluteDisplayOrder &&
|
||||
x.UnitConverision == y.UnitConverision;
|
||||
}
|
||||
|
||||
// If Equals() returns true for a pair of objects,
|
||||
// GetHashCode must return the same value for these objects.
|
||||
|
||||
public int GetHashCode(AnalogInputDASChannel analog)
|
||||
{
|
||||
// Check whether the object is null.
|
||||
|
||||
if (string.IsNullOrEmpty(analog.OwningModule?.OwningDAS?.SerialNumber))
|
||||
return 0;
|
||||
|
||||
// Get the hash code for the fields
|
||||
return analog.ModuleChannelNumber.GetHashCode() ^
|
||||
analog.OwningModule.ModuleArrayIndex.GetHashCode() ^
|
||||
analog.OwningModule.OwningDAS.SerialNumber.GetHashCode() ^
|
||||
analog.AbsoluteDisplayOrder.GetHashCode() ^
|
||||
analog.UnitConverision.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user