/// <summary> /// Creates an RDN object from the DN component specified in the string RDN. /// </summary> /// <param name="rdn"> /// the DN component. /// </param> public Rdn(string rdn) { RawValue = rdn; var dn = new Dn(rdn); var rdns = dn.RdNs; // there should only be one rdn if (rdns.Count != 1) { throw new ArgumentException("Invalid RDN: see API " + "documentation"); } var thisRdn = rdns[0]; _types = thisRdn._types; _values = thisRdn._values; RawValue = thisRdn.RawValue; }
public bool Equals(Dn toDn) { var aList = toDn.GetRdnList(); var length = aList.Count; if (_rdnList.Count != length) { return(false); } for (var i = 0; i < length; i++) { if (!(_rdnList[i]).Equals(toDn.GetRdnList()[i])) { return(false); } } return(true); }
/// <summary> /// Determines if this DN is <I>contained</I> by the DN passed in. For /// example: "cn=admin, ou=marketing, o=corporation" is contained by /// "o=corporation", "ou=marketing, o=corporation", and "ou=marketing" /// but <B>not</B> by "cn=admin" or "cn=admin,ou=marketing,o=corporation" /// Note: For users of Netscape's SDK this method is comparable to contains. /// </summary> /// <param name="containerDn"> /// of a container. /// </param> /// <returns> /// true if containerDN contains this DN. /// </returns> public bool IsDescendantOf(Dn containerDn) { var i = containerDn._rdnList.Count - 1; // index to an RDN of the ContainerDN var j = _rdnList.Count - 1; // index to an RDN of the ContainedDN // Search from the end of the DN for an RDN that matches the end RDN of // containerDN. while (!(_rdnList[j]).Equals(containerDn._rdnList[i])) { j--; if (j <= 0) { return(false); } // if the end RDN of containerDN does not have any equal // RDN in rdnList, then containerDN does not contain this DN } i--; // avoid a redundant compare j--; // step backwards to verify that all RDNs in containerDN exist in this DN for (; i >= 0 && j >= 0; i--, j--) { if (!(_rdnList[j]).Equals(containerDn._rdnList[i])) { return(false); } } if (j == 0 && i == 0) // the DNs are identical and thus not contained { return(false); } return(true); }