using System; namespace DnsClient.Protocol { public abstract class DnsResourceRecord : ResourceRecordInfo { public DnsResourceRecord(ResourceRecordInfo info) : base(info.QueryName, info.RecordType, info.RecordClass, info.TimeToLive, info.RawDataLength) { } /// public override string ToString() { return ToString(0); } /// /// Same as ToString but offsets the /// by . /// Set the offset to -32 for example to make it print nicely in consols. /// /// The offset. /// A string representing this instance. public virtual string ToString(int offset = 0) { return string.Format("{0," + offset + "}{1} \t{2} \t{3} \t{4}", QueryName, TimeToLive, RecordClass, RecordType, RecordToString()); } /// /// Returns the actual record's value only and not the full object representation. /// uses this to compose the full string value of this instance. /// /// A string representing this record. public abstract string RecordToString(); } public class ResourceRecordInfo { /// /// The query name. /// public string QueryName { get; } /// /// Specifies type of resource record. /// public ResourceRecordType RecordType { get; } /// /// Specifies type class of resource record, mostly IN but can be CS, CH or HS . /// public QueryClass RecordClass { get; } /// /// The TTL value for the record set by the server. /// public uint TimeToLive { get; } /// /// Gets the number of bytes for this resource record stored in RDATA /// public int RawDataLength { get; } public ResourceRecordInfo(string queryName, ResourceRecordType recordType, QueryClass recordClass, uint ttl, int length) { if (queryName == null) { throw new ArgumentNullException(nameof(queryName)); } QueryName = queryName; RecordType = recordType; RecordClass = recordClass; TimeToLive = ttl; RawDataLength = length; } } }