Skip to content

Commit

Permalink
Implement mx operators
Browse files Browse the repository at this point in the history
  • Loading branch information
coder2000 committed Jun 18, 2018
1 parent 0062ff7 commit c7f4ca8
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 41 deletions.
4 changes: 1 addition & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,4 @@ deploy:
secure: +fxguAe7QHo5zfhN7YRoOqMf4x8ZG4mR29Q8HMY0Y9d4gvwv+NP5daWbQyc0R/BJ
artifact: /.*\.nupkg/
draft: true
prerelease: true
on:
branch: develop
prerelease: true
108 changes: 70 additions & 38 deletions src/Ubiety.Dns.Core/Records/Mail/RecordMX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ namespace Ubiety.Dns.Core.Records.Mail
/*
3.3.9. MX RDATA format
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| PREFERENCE |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/ EXCHANGE /
/ /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
where:
Expand All @@ -28,12 +22,26 @@ specified by EXCHANGE. The use of MX RRs is explained in detail in
*/

/// <summary>
/// Mail exchange DNS record
/// Mail exchange DNS record
/// </summary>
/// <remarks>
/// # [Description](#tab/description)
/// Standard MX mail DNS record
///
/// # [RFC](#tab/rfc)
/// ```
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// | PREFERENCE |
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// / EXCHANGE /
/// / /
/// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
/// ```
/// </remarks>
public sealed class RecordMx : Record, IComparable, IEquatable<RecordMx>
{
/// <summary>
/// Initializes a new instance of the <see cref="RecordMx" /> class
/// Initializes a new instance of the <see cref="RecordMx" /> class
/// </summary>
/// <param name="rr"><see cref="RecordReader" /> for the record data</param>
public RecordMx(RecordReader rr)
Expand All @@ -43,17 +51,17 @@ public RecordMx(RecordReader rr)
}

/// <summary>
/// Gets or sets the preference
/// Gets or sets the preference
/// </summary>
public UInt16 Preference { get; set; }

/// <summary>
/// Gets or sets the exchange
/// Gets or sets the exchange
/// </summary>
public String Exchange { get; set; }

/// <summary>
/// String representation of the record data
/// String representation of the record data
/// </summary>
/// <returns>Exchange and preference as a string</returns>
public override String ToString()
Expand All @@ -62,93 +70,117 @@ public override String ToString()
}

/// <summary>
/// Compares record to an object
/// Compares record to an object
/// </summary>
/// <param name="obj">Object to compare record to</param>
/// <returns>Int value of the comparison</returns>
public int CompareTo(object obj)
{
RecordMx recordMX = obj as RecordMx;
if (recordMX == null)
{
return -1;
}
else if (this.Preference > recordMX.Preference)
return CompareTo(this, obj as RecordMx);
}

/// <summary>
/// </summary>
public override Boolean Equals(object obj)
{
if (obj is null)
{
return 1;
return false;
}
else if (this.Preference < recordMX.Preference)

if (this.GetType() != obj.GetType())
{
return -1;
return false;
}
else

if (ReferenceEquals(this, obj))
{
// they are the same, now compare case insensitive names
return string.Compare(this.Exchange, recordMX.Exchange, true, CultureInfo.InvariantCulture);
return true;
}
}

/// <summary>
/// </summary>
public override Boolean Equals(object obj)
{
throw new NotImplementedException();
return this.Equals(obj as RecordMx);
}

/// <summary>
/// </summary>
public override Int32 GetHashCode()
{
throw new NotImplementedException();
return Exchange.GetHashCode();
}

/// <summary>
/// </summary>
public Boolean Equals(RecordMx other)
{
throw new NotImplementedException();
if (other is null)
{
return false;
}

return CompareTo(this, other) == 0;
}

/// <summary>
/// </summary>
public static Boolean operator <(RecordMx x, RecordMx y)
{
throw new NotImplementedException();
return CompareTo(x, y) < 0;
}

/// <summary>
/// </summary>
public static Boolean operator >(RecordMx x, RecordMx y)
{
throw new NotImplementedException();
return CompareTo(x, y) > 0;
}

/// <summary>
/// </summary>
public static Boolean operator <=(RecordMx x, RecordMx y)
{
throw new NotImplementedException();
return CompareTo(x, y) <= 0;
}

/// <summary>
/// </summary>
public static Boolean operator >=(RecordMx x, RecordMx y)
{
throw new NotImplementedException();
return CompareTo(x, y) >= 0;
}

/// <summary>
/// </summary>
public static Boolean operator ==(RecordMx x, RecordMx y)
{
throw new NotImplementedException();
return CompareTo(x, y) == 0;
}

/// <summary>
/// </summary>
public static Boolean operator !=(RecordMx x, RecordMx y)
{
throw new NotImplementedException();
return CompareTo(x, y) != 0;
}

private static Int32 CompareTo(RecordMx x, RecordMx y)
{
if (y == null)
{
return -1;
}
else if (x.Preference > y.Preference)
{
return 1;
}
else if (x.Preference < y.Preference)
{
return -1;
}
else
{
// they are the same, now compare case insensitive names
return string.Compare(x.Exchange, y.Exchange, true, CultureInfo.InvariantCulture);
}
}
}
}

0 comments on commit c7f4ca8

Please sign in to comment.