/// <summary> /// Check class equality with argument. /// /// Accepted argument types are: /// * Integer32 - compared against the request id /// * Pdu - compared against PduType, request id and contents of VarBind list /// </summary> /// <param name="obj">Integer32 or Pdu to compare</param> /// <returns>True if equal, otherwise false</returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj is Integer32) { if (((Integer32)obj) == _requestId) { return(true); } return(false); } else if (obj is Pdu p) { if (p.Type != Type) { return(false); } if (p.RequestId != RequestId) { return(false); } if (p.VbCount != VbCount) { return(false); } foreach (Vb v in VbList) { if (!p.VbList.ContainsOid(v.Oid)) { return(false); } } foreach (Vb v in p.VbList) { if (!VbList.ContainsOid(v.Oid)) { return(false); } } return(true); } return(false); }
/// <summary>Access variable bindings using Vb Oid value</summary> /// <param name="oid">Required Oid value</param> /// <returns>Variable binding with the Oid matching the parameter, otherwise null</returns> public Vb this[Oid oid] { get { if (!VbList.ContainsOid(oid)) { return(null); } foreach (Vb v in VbList) { if (v.Oid.Equals(oid)) { return(v); } } return(null); } }
/// <summary> /// Check class equality with argument. /// /// Accepted argument types are: /// * Integer32 - compared against the request id /// * Pdu - compared against PduType, request id and contents of VarBind list /// </summary> /// <param name="obj">Integer32 or Pdu to compare</param> /// <returns>True if equal, otherwise false</returns> public bool Equals(Pdu obj) { if (obj == null) { return(false); } Pdu p = (Pdu)obj; if (p.Type != this.Type) { return(false); } if (p.RequestId != this.RequestId) { return(false); } if (p.VbCount != this.VbCount) { return(false); } foreach (Vb v in VbList) { if (!p.VbList.ContainsOid(v.Oid)) { return(false); } } foreach (Vb v in p.VbList) { if (!VbList.ContainsOid(v.Oid)) { return(false); } } return(true); }