public string ToString(string header, string other = null) { string result = String.Format("{0}[{1},{2}", header, DNSEntry.GetType(this.Type), DNSEntry.GetClass(this.Class)); if (this.Unique) { result += "-unique,"; } else { result += ","; } result += this.Name; if (other != null) { result += String.Format(",{0}]", other); } else { result += "]"; } return(result); }
public override bool Equals(Object obj) { DNSEntry other = obj as DNSEntry; return(this.Name == other.Name && this.Type == other.Type && this.Class == other.Class); }
/// <summary> /// Removes an entry /// </summary> /// <param name="entry">Entry.</param> public void Remove(DNSEntry entry) { if (this.cache.ContainsKey(entry.Key)) { List <DNSEntry> records = this.cache[entry.Key]; records.Remove(entry); } }
/// <summary> /// Adds an entry /// </summary> /// <param name="entry">DNS Record to add.</param> public void Add(DNSEntry entry) { List <DNSEntry> records; bool success = this.cache.TryGetValue(entry.Key, out records); if (!success) { records = new List <DNSEntry>(); } records.Insert(0, entry); this.cache[entry.Key] = records; }
/// <summary> /// Gets an entry by key. /// </summary> /// <returns><c>DNSEntry</c> if entry is found, <c>null</c> otherwise</returns> /// <param name="entry">Entry.</param> public DNSEntry Get(DNSEntry entry) { if (this.cache.ContainsKey(entry.Key)) { List <DNSEntry> records = this.cache[entry.Key]; foreach (DNSEntry cachedEntry in records) { if (entry.Equals(cachedEntry)) { return(cachedEntry); } } } return(null); }
/// <summary> /// Gets an entry by details /// </summary> /// <returns><c>DNSEntry</c> if entry is found, <c>null</c> otherwise</returns> /// <param name="name">Name.</param> /// <param name="type">Type.</param> /// <param name="cls">Cls.</param> public DNSEntry GetByDetails(string name, DNSType type, DNSClass cls) { DNSEntry entry = new DNSEntry(name, type, cls); return(Get(entry)); }