Commit 35ef2046 authored by Brickner_cp's avatar Brickner_cp

Warnings, Code Analysis and Documentation. 383 warnings left.

parent 4cd2af48
...@@ -13,6 +13,9 @@ namespace PcapDotNet.Base ...@@ -13,6 +13,9 @@ namespace PcapDotNet.Base
public static class IEnumerableExtensions public static class IEnumerableExtensions
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
{ {
/// <summary>
/// Returns true if the given enumerable is null or empty.
/// </summary>
public static bool IsNullOrEmpty<T>(this IEnumerable<T> sequence) public static bool IsNullOrEmpty<T>(this IEnumerable<T> sequence)
{ {
return sequence == null || !sequence.Any(); return sequence == null || !sequence.Any();
...@@ -223,16 +226,45 @@ namespace PcapDotNet.Base ...@@ -223,16 +226,45 @@ namespace PcapDotNet.Base
return sequence.Count(element => element.Equals(value)); return sequence.Count(element => element.Equals(value));
} }
/// <summary>
/// Returns true iff the given sequence is strictly ordered using the elements as keys and a default comparer.
/// </summary>
/// <typeparam name="T">The type of the objects in the sequence that will be used as keys for comparison using a default comparer.</typeparam>
/// <param name="sequence">The sequence of elements to check for strict order.</param>
/// <returns>True iff the sequence is strictly ordered.</returns>
public static bool IsStrictOrdered<T>(this IEnumerable<T> sequence) public static bool IsStrictOrdered<T>(this IEnumerable<T> sequence)
{ {
return IsStrictOrdered(sequence, element => element); return IsStrictOrdered(sequence, element => element);
} }
/// <summary>
/// Returns true iff the given sequence is strictly ordered using the by keys computed using a given function and a default comparer.
/// </summary>
/// <typeparam name="T">
/// The type of the objects in the sequence that will that will be operated with the given key selector function to get the keys
/// to compare using a default comparer.
/// </typeparam>
/// <typeparam name="TKey">The type of the keys to compare using a default comparer.</typeparam>
/// <param name="sequence">The sequence of elements to check for strict order.</param>
/// <param name="keySelector">The function to operate on the sequence elements to get the keys to compare.</param>
/// <returns>True iff the sequence is strictly ordered.</returns>
public static bool IsStrictOrdered<T, TKey>(this IEnumerable<T> sequence, Func<T, TKey> keySelector) public static bool IsStrictOrdered<T, TKey>(this IEnumerable<T> sequence, Func<T, TKey> keySelector)
{ {
return IsStrictOrdered(sequence, keySelector, Comparer<TKey>.Default); return IsStrictOrdered(sequence, keySelector, Comparer<TKey>.Default);
} }
/// <summary>
/// Returns true iff the given sequence is strictly ordered using the by keys computed using a given function and a given comparer.
/// </summary>
/// <typeparam name="T">
/// The type of the objects in the sequence that will that will be operated with the given key selector function to get the keys
/// to compare using a given comparer.
/// </typeparam>
/// <typeparam name="TKey">The type of the keys to compare using a given comparer.</typeparam>
/// <param name="sequence">The sequence of elements to check for strict order.</param>
/// <param name="keySelector">The function to operate on the sequence elements to get the keys to compare.</param>
/// <param name="comparer">The comparer to use to compare the computed keys.</param>
/// <returns>True iff the sequence is strictly ordered.</returns>
public static bool IsStrictOrdered<T, TKey>(this IEnumerable<T> sequence, Func<T, TKey> keySelector, IComparer<TKey> comparer) public static bool IsStrictOrdered<T, TKey>(this IEnumerable<T> sequence, Func<T, TKey> keySelector, IComparer<TKey> comparer)
{ {
if (comparer == null) if (comparer == null)
......
...@@ -7,6 +7,9 @@ namespace PcapDotNet.Base ...@@ -7,6 +7,9 @@ namespace PcapDotNet.Base
/// </summary> /// </summary>
public static class Sequence public static class Sequence
{ {
/// <summary>
/// Returns the xor of the hash codes of the given objects.
/// </summary>
public static int GetHashCode(object value1, object value2) public static int GetHashCode(object value1, object value2)
{ {
if (value1 == null) if (value1 == null)
...@@ -17,6 +20,9 @@ namespace PcapDotNet.Base ...@@ -17,6 +20,9 @@ namespace PcapDotNet.Base
return value1.GetHashCode() ^ value2.GetHashCode(); return value1.GetHashCode() ^ value2.GetHashCode();
} }
/// <summary>
/// Returns the xor of the hash codes of the given objects.
/// </summary>
public static int GetHashCode(object value1, object value2, object value3) public static int GetHashCode(object value1, object value2, object value3)
{ {
if (value3 == null) if (value3 == null)
...@@ -25,6 +31,9 @@ namespace PcapDotNet.Base ...@@ -25,6 +31,9 @@ namespace PcapDotNet.Base
return GetHashCode(value1, value2) ^ value3.GetHashCode(); return GetHashCode(value1, value2) ^ value3.GetHashCode();
} }
/// <summary>
/// Returns the xor of the hash codes of the given objects.
/// </summary>
public static int GetHashCode(params object[] values) public static int GetHashCode(params object[] values)
{ {
if (values == null) if (values == null)
......
...@@ -3,19 +3,46 @@ using System.Globalization; ...@@ -3,19 +3,46 @@ using System.Globalization;
namespace PcapDotNet.Base namespace PcapDotNet.Base
{ {
/// <summary>
/// A 32 bit serial number as defined in RFC 1982.
/// </summary>
public struct SerialNumber32 : IEquatable<SerialNumber32>, IComparable<SerialNumber32> public struct SerialNumber32 : IEquatable<SerialNumber32>, IComparable<SerialNumber32>
{ {
/// <summary>
/// The number of bytes this type takes.
/// </summary>
public const int SizeOf = sizeof(uint); public const int SizeOf = sizeof(uint);
/// <summary>
/// Number of bits of the serial number.
/// </summary>
public const int SerialBits = 32; public const int SerialBits = 32;
/// <summary>
/// The maximum value that can be added to the serial number.
/// </summary>
public const uint MaxAdditiveNumber = ((uint)1 << (SerialBits - 1)) - 1; public const uint MaxAdditiveNumber = ((uint)1 << (SerialBits - 1)) - 1;
/// <summary>
/// Constructs a serial number from an unsigned value.
/// </summary>
/// <param name="value">The value to set the serial number.</param>
public SerialNumber32(uint value) public SerialNumber32(uint value)
{ {
_value = value; _value = value;
} }
/// <summary>
/// The value of the serial number.
/// </summary>
public uint Value { get { return _value; } } public uint Value { get { return _value; } }
/// <summary>
/// Adds a value to the serial number and returns the result.
/// <paramref name="value"/> should not be bigger than <see cref="MaxAdditiveNumber"/>.
/// </summary>
/// <param name="value">The value to add.</param>
/// <returns>A new serial number that represents the sum of the original serial number and <paramref name="value"/>.</returns>
public SerialNumber32 Add(uint value) public SerialNumber32 Add(uint value)
{ {
if (value > MaxAdditiveNumber) if (value > MaxAdditiveNumber)
...@@ -25,22 +52,47 @@ namespace PcapDotNet.Base ...@@ -25,22 +52,47 @@ namespace PcapDotNet.Base
return _value + value; return _value + value;
} }
/// <summary>
/// Two serial numbers are equal if their value is equal.
/// </summary>
/// <param name="other">The object to compare to.</param>
/// <returns>True iff the two serial numbers are equal.</returns>
public bool Equals(SerialNumber32 other) public bool Equals(SerialNumber32 other)
{ {
return Value == other.Value; return Value == other.Value;
} }
/// <summary>
/// Two serial numbers are equal if their value is equal.
/// </summary>
/// <param name="obj">The object to compare to.</param>
/// <returns>True iff the two serial numbers are equal.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
return obj is SerialNumber32 && return obj is SerialNumber32 &&
Equals((SerialNumber32)obj); Equals((SerialNumber32)obj);
} }
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>A 32-bit signed integer that is the hash code for this instance.</returns>
public override int GetHashCode() public override int GetHashCode()
{ {
return Value.GetHashCode(); return Value.GetHashCode();
} }
/// <summary>
/// Compares the current object with another object of the same type.
/// </summary>
/// <returns>
/// A value that indicates the relative order of the objects being compared.
/// The return value has the following meanings:
/// Value Meaning Less than zero This object is less than the <paramref name="other"/>.
/// parameter.Zero This object is equal to <paramref name="other"/>.
/// Greater than zero This object is greater than <paramref name="other"/>.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public int CompareTo(SerialNumber32 other) public int CompareTo(SerialNumber32 other)
{ {
if (Equals(other)) if (Equals(other))
...@@ -51,36 +103,74 @@ namespace PcapDotNet.Base ...@@ -51,36 +103,74 @@ namespace PcapDotNet.Base
return (Value - other.Value < MaxAdditiveNumber + 1 ? 1 : -1); return (Value - other.Value < MaxAdditiveNumber + 1 ? 1 : -1);
} }
/// <summary>
/// The string representation of this serial number.
/// </summary>
/// <returns>A string representing this serial number.</returns>
public override string ToString() public override string ToString()
{ {
return ToString(CultureInfo.InvariantCulture); return ToString(CultureInfo.InvariantCulture);
} }
///<summary>
/// The string representation of this serial number using the given format provider.
///</summary>
///<param name="provider">The format of the output string.</param>
///<returns>A string representing this serial number using the given format provider.</returns>
public string ToString(IFormatProvider provider) public string ToString(IFormatProvider provider)
{ {
return Value.ToString(provider); return Value.ToString(provider);
} }
/// <summary>
/// Implicitly cast a uint to a serial number.
/// </summary>
/// <param name="value">The value to cast.</param>
/// <returns>The casted value.</returns>
public static implicit operator SerialNumber32(uint value) public static implicit operator SerialNumber32(uint value)
{ {
return new SerialNumber32(value); return new SerialNumber32(value);
} }
/// <summary>
/// Returns true iff the two serial numbers are equal.
/// </summary>
/// <param name="value1">First serial number to compare.</param>
/// <param name="value2">Second serial number to compare.</param>
/// <returns>True iff the two serial numbers are equal.</returns>
public static bool operator ==(SerialNumber32 value1, SerialNumber32 value2) public static bool operator ==(SerialNumber32 value1, SerialNumber32 value2)
{ {
return value1.Equals(value2); return value1.Equals(value2);
} }
/// <summary>
/// Returns true iff the two serial numbers are not equal.
/// </summary>
/// <param name="value1">First serial number to compare.</param>
/// <param name="value2">Second serial number to compare.</param>
/// <returns>True iff the two serial numbers are not equal.</returns>
public static bool operator !=(SerialNumber32 value1, SerialNumber32 value2) public static bool operator !=(SerialNumber32 value1, SerialNumber32 value2)
{ {
return !(value1 == value2); return !(value1 == value2);
} }
/// <summary>
/// Returns true iff the first serial number is smaller than the second serial number.
/// </summary>
/// <param name="value1">First serial number to compare.</param>
/// <param name="value2">Second serial number to compare.</param>
/// <returns>True iff the first serial number is smaller than the second serial number..</returns>
public static bool operator <(SerialNumber32 value1, SerialNumber32 value2) public static bool operator <(SerialNumber32 value1, SerialNumber32 value2)
{ {
return value1.CompareTo(value2) < 0; return value1.CompareTo(value2) < 0;
} }
/// <summary>
/// Returns true iff the first serial number is greater than the second serial number.
/// </summary>
/// <param name="value1">First serial number to compare.</param>
/// <param name="value2">Second serial number to compare.</param>
/// <returns>True iff the first serial number is greater than the second serial number..</returns>
public static bool operator >(SerialNumber32 value1, SerialNumber32 value2) public static bool operator >(SerialNumber32 value1, SerialNumber32 value2)
{ {
return value1.CompareTo(value2) > 0; return value1.CompareTo(value2) > 0;
......
...@@ -31,6 +31,9 @@ namespace PcapDotNet.Base ...@@ -31,6 +31,9 @@ namespace PcapDotNet.Base
/// </summary> /// </summary>
public static readonly UInt128 Zero = 0; public static readonly UInt128 Zero = 0;
/// <summary>
/// A One UInt128 value.
/// </summary>
public static readonly UInt128 One = 1; public static readonly UInt128 One = 1;
/// <summary> /// <summary>
...@@ -361,6 +364,17 @@ namespace PcapDotNet.Base ...@@ -361,6 +364,17 @@ namespace PcapDotNet.Base
Equals((UInt128)obj); Equals((UInt128)obj);
} }
/// <summary>
/// Compares the current object with another object of the same type.
/// </summary>
/// <returns>
/// A value that indicates the relative order of the objects being compared.
/// The return value has the following meanings:
/// Less than zero - This object is less than the <paramref name="other"/>.
/// parameter.Zero - This object is equal to <paramref name="other"/>.
/// Greater than zero - This object is greater than <paramref name="other"/>.
/// </returns>
/// <param name="other">An object to compare with this object.</param>
public int CompareTo(UInt128 other) public int CompareTo(UInt128 other)
{ {
if (_mostSignificant != other._mostSignificant) if (_mostSignificant != other._mostSignificant)
...@@ -390,21 +404,45 @@ namespace PcapDotNet.Base ...@@ -390,21 +404,45 @@ namespace PcapDotNet.Base
return !(value1 == value2); return !(value1 == value2);
} }
/// <summary>
/// Returns true iff the first value is smaller than the second value.
/// </summary>
/// <param name="value1">The first value to compare.</param>
/// <param name="value2">The second value to compare.</param>
/// <returns>True iff the first value is smaller than the second value.</returns>
public static bool operator <(UInt128 value1, UInt128 value2) public static bool operator <(UInt128 value1, UInt128 value2)
{ {
return value1.CompareTo(value2) < 0; return value1.CompareTo(value2) < 0;
} }
/// <summary>
/// Returns true iff the first value is greater than the second value.
/// </summary>
/// <param name="value1">The first value to compare.</param>
/// <param name="value2">The second value to compare.</param>
/// <returns>True iff the first value is greater than the second value.</returns>
public static bool operator >(UInt128 value1, UInt128 value2) public static bool operator >(UInt128 value1, UInt128 value2)
{ {
return value1.CompareTo(value2) > 0; return value1.CompareTo(value2) > 0;
} }
/// <summary>
/// Returns true iff the first value is smaller than or equal to the second value.
/// </summary>
/// <param name="value1">The first value to compare.</param>
/// <param name="value2">The second value to compare.</param>
/// <returns>True iff the first value is smaller than or equal to the second value.</returns>
public static bool operator <=(UInt128 value1, UInt128 value2) public static bool operator <=(UInt128 value1, UInt128 value2)
{ {
return value1.CompareTo(value2) <= 0; return value1.CompareTo(value2) <= 0;
} }
/// <summary>
/// Returns true iff the first value is greater than or equal to the second value.
/// </summary>
/// <param name="value1">The first value to compare.</param>
/// <param name="value2">The second value to compare.</param>
/// <returns>True iff the first value is greater than or equal to the second value.</returns>
public static bool operator >=(UInt128 value1, UInt128 value2) public static bool operator >=(UInt128 value1, UInt128 value2)
{ {
return value1.CompareTo(value2) >= 0; return value1.CompareTo(value2) >= 0;
...@@ -487,11 +525,23 @@ namespace PcapDotNet.Base ...@@ -487,11 +525,23 @@ namespace PcapDotNet.Base
return new UInt128(value1._mostSignificant & value2._mostSignificant, value1._leastSignificant & value2._leastSignificant); return new UInt128(value1._mostSignificant & value2._mostSignificant, value1._leastSignificant & value2._leastSignificant);
} }
/// <summary>
/// Sums the given values and returns the sum.
/// </summary>
/// <param name="value1">The first value to sum.</param>
/// <param name="value2">The second value to sum.</param>
/// <returns>The sum of the given values.</returns>
public static UInt128 operator +(UInt128 value1, UInt128 value2) public static UInt128 operator +(UInt128 value1, UInt128 value2)
{ {
return Add(value1, value2); return Add(value1, value2);
} }
/// <summary>
/// Sums the given values and returns the sum.
/// </summary>
/// <param name="value1">The first value to sum.</param>
/// <param name="value2">The second value to sum.</param>
/// <returns>The sum of the given values.</returns>
public static UInt128 Add(UInt128 value1, UInt128 value2) public static UInt128 Add(UInt128 value1, UInt128 value2)
{ {
ulong leastSignificant = value1._leastSignificant + value2._leastSignificant; ulong leastSignificant = value1._leastSignificant + value2._leastSignificant;
...@@ -499,11 +549,23 @@ namespace PcapDotNet.Base ...@@ -499,11 +549,23 @@ namespace PcapDotNet.Base
return new UInt128(value1._mostSignificant + value2._mostSignificant + (ulong)(overflow ? 1 : 0), leastSignificant); return new UInt128(value1._mostSignificant + value2._mostSignificant + (ulong)(overflow ? 1 : 0), leastSignificant);
} }
/// <summary>
/// Substract the second value from the first value and returns the result of the substraction.
/// </summary>
/// <param name="value1">The first value to sum.</param>
/// <param name="value2">The second value to sum.</param>
/// <returns>The result of substracting the second value from the first value.</returns>
public static UInt128 operator -(UInt128 value1, UInt128 value2) public static UInt128 operator -(UInt128 value1, UInt128 value2)
{ {
return Subtract(value1, value2); return Subtract(value1, value2);
} }
/// <summary>
/// Substract the second value from the first value and returns the result of the substraction.
/// </summary>
/// <param name="value1">The first value to sum.</param>
/// <param name="value2">The second value to sum.</param>
/// <returns>The result of substracting the second value from the first value.</returns>
public static UInt128 Subtract(UInt128 value1, UInt128 value2) public static UInt128 Subtract(UInt128 value1, UInt128 value2)
{ {
ulong leastSignificant = value1._leastSignificant - value2._leastSignificant; ulong leastSignificant = value1._leastSignificant - value2._leastSignificant;
......
...@@ -29,6 +29,11 @@ namespace PcapDotNet.Base ...@@ -29,6 +29,11 @@ namespace PcapDotNet.Base
return new UInt24(value); return new UInt24(value);
} }
/// <summary>
/// Converts a 32 bit unsigned integer to a 24 bit unsigned integer by taking the 24 least significant bits.
/// </summary>
/// <param name="value">The 32 bit value to convert.</param>
/// <returns>The 24 bit value created by taking the 24 least significant bits of the 32 bit value.</returns>
public static explicit operator UInt24(uint value) public static explicit operator UInt24(uint value)
{ {
return new UInt24((int)value); return new UInt24((int)value);
......
...@@ -536,29 +536,30 @@ namespace PcapDotNet.Base ...@@ -536,29 +536,30 @@ namespace PcapDotNet.Base
/// <returns> /// <returns>
/// A 32-bit signed integer that is the hash code for this instance. /// A 32-bit signed integer that is the hash code for this instance.
/// </returns> /// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode() public override int GetHashCode()
{ {
return ((long)this).GetHashCode(); return ((long)this).GetHashCode();
} }
/// <summary> /// <summary>
/// Returns the fully qualified type name of this instance. /// Returns a string representing the value using a default format and an invariant culture format provider.
/// </summary> /// </summary>
/// <returns>
/// A <see cref="T:System.String"/> containing a fully qualified type name.
/// </returns>
/// <filterpriority>2</filterpriority>
public override string ToString() public override string ToString()
{ {
return ((long)this).ToString(CultureInfo.InvariantCulture); return ((long)this).ToString(CultureInfo.InvariantCulture);
} }
/// <summary>
/// Returns a string representing the value using the given string format and an invariant culture format provider.
/// </summary>
public string ToString(string format) public string ToString(string format)
{ {
return ToString(format, CultureInfo.InvariantCulture); return ToString(format, CultureInfo.InvariantCulture);
} }
/// <summary>
/// Returns a string representing the value using the given string format and the given format provider.
/// </summary>
public string ToString(string format, IFormatProvider provider) public string ToString(string format, IFormatProvider provider)
{ {
return ((long)this).ToString(format, provider); return ((long)this).ToString(format, provider);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment