Commit b59c4532 authored by Brickner_cp's avatar Brickner_cp

Warnings, Code Analysis and Documentation. 216 warnings left.

parent 8dcb5280
namespace PcapDotNet.Base namespace PcapDotNet.Base
{ {
/// <summary>
/// Extension methods for char structure.
/// </summary>
public static class CharExtensions public static class CharExtensions
{ {
public static bool IsUpperCaseAlpha(this char c) /// <summary>
/// True iff the given character is one of the capital english letters.
/// </summary>
/// <param name="character">The input character to check.</param>
/// <returns>True for capital english letters.</returns>
public static bool IsUppercaseAlpha(this char character)
{ {
return c >= 'A' && c <= 'Z'; return character >= 'A' && character <= 'Z';
} }
} }
} }
\ No newline at end of file
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace PcapDotNet.Base namespace PcapDotNet.Base
{ {
/// <summary>
/// Extension methods for IDictionary&lt;TKey,TValue> interface.
/// </summary>
public static class IDictionaryExtensions public static class IDictionaryExtensions
{ {
/// <summary>
/// Tests for equality between dictionaries.
/// Two dictionaries are equal if they have the same pairs.
/// Keys are compared using Equals() and values are compared using the given comparator.
/// </summary>
/// <typeparam name="TKey">The type of the key of the dictionary.</typeparam>
/// <typeparam name="TValue">The type of the value of the dictionary.</typeparam>
/// <param name="dictionary1">The first dictionary to compare.</param>
/// <param name="dictionary2">The second dictionary to compare.</param>
/// <param name="valueComparer">The comparator to check for values equality.</param>
/// <returns>True iff the dictionaries are equal.</returns>
public static bool DictionaryEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary1, IDictionary<TKey, TValue> dictionary2, IEqualityComparer<TValue> valueComparer) public static bool DictionaryEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary1, IDictionary<TKey, TValue> dictionary2, IEqualityComparer<TValue> valueComparer)
{ {
if (valueComparer == null)
throw new ArgumentNullException("valueComparer");
if (ReferenceEquals(dictionary1, dictionary2)) if (ReferenceEquals(dictionary1, dictionary2))
return true; return true;
...@@ -27,6 +45,16 @@ namespace PcapDotNet.Base ...@@ -27,6 +45,16 @@ namespace PcapDotNet.Base
return true; return true;
} }
/// <summary>
/// Tests for equality between dictionaries.
/// Two dictionaries are equal if they have the same pairs.
/// Keys are compared using Equals() and values are compared using the default EqualityComparer.
/// </summary>
/// <typeparam name="TKey">The type of the key of the dictionary.</typeparam>
/// <typeparam name="TValue">The type of the value of the dictionary.</typeparam>
/// <param name="dictionary1">The first dictionary to compare.</param>
/// <param name="dictionary2">The second dictionary to compare.</param>
/// <returns>True iff the dictionaries are equal.</returns>
public static bool DictionaryEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary1, IDictionary<TKey, TValue> dictionary2) public static bool DictionaryEquals<TKey, TValue>(this IDictionary<TKey, TValue> dictionary1, IDictionary<TKey, TValue> dictionary2)
{ {
return dictionary1.DictionaryEquals(dictionary2, EqualityComparer<TValue>.Default); return dictionary1.DictionaryEquals(dictionary2, EqualityComparer<TValue>.Default);
......
...@@ -90,6 +90,13 @@ namespace PcapDotNet.Base ...@@ -90,6 +90,13 @@ namespace PcapDotNet.Base
return sequence.SequenceToString(separator, string.Empty); return sequence.SequenceToString(separator, string.Empty);
} }
/// <summary>
/// Converts a sequence to a string by converting each element to a string.
/// </summary>
/// <typeparam name="T">The type of an element in the sequence.</typeparam>
/// <param name="sequence">The sequence with the elements to translate to string.</param>
/// <param name="separator">A separator between the elements.</param>
/// <returns>A string of all the elements.</returns>
public static string SequenceToString<T>(this IEnumerable<T> sequence, char separator) public static string SequenceToString<T>(this IEnumerable<T> sequence, char separator)
{ {
return sequence.SequenceToString(separator.ToString()); return sequence.SequenceToString(separator.ToString());
......
...@@ -22,6 +22,14 @@ namespace PcapDotNet.Base ...@@ -22,6 +22,14 @@ namespace PcapDotNet.Base
return new ReadOnlyCollection<T>(list); return new ReadOnlyCollection<T>(list);
} }
/// <summary>
/// Returns an enumerable of all the elements in the given list starting in a specific offset and taking no more than a specific count.
/// </summary>
/// <typeparam name="T">The type of an element in the collection.</typeparam>
/// <param name="list">The list to take the elements from.</param>
/// <param name="offset">The offset of the first element to take.</param>
/// <param name="count">The maximum number of elements to take.</param>
/// <returns>An enumerable of all the elements in the given list starting in a specific offset and taking no more than a specific count.</returns>
public static IEnumerable<T> Range<T>(this IList<T> list, int offset, int count) public static IEnumerable<T> Range<T>(this IList<T> list, int offset, int count)
{ {
int length = Math.Min(offset + count, list.Count); int length = Math.Min(offset + count, list.Count);
......
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Linq; using System.Linq;
namespace PcapDotNet.Base namespace PcapDotNet.Base
{ {
/// <summary>
/// Extension methods for Match class.
/// </summary>
public static class MatchExtensions public static class MatchExtensions
{ {
/// <summary>
/// Returns all the values that were captured for a given group name.
/// </summary>
/// <param name="match">The match to take the captured values from.</param>
/// <param name="groupName">The name of the capture group to take the values of.</param>
/// <returns>All the values that were captured for a given group name.</returns>
public static IEnumerable<string> GroupCapturesValues(this Match match, string groupName) public static IEnumerable<string> GroupCapturesValues(this Match match, string groupName)
{ {
if (match == null)
throw new ArgumentNullException("match");
return match.Groups[groupName].Captures.Cast<Capture>().Select(capture => capture.Value); return match.Groups[groupName].Captures.Cast<Capture>().Select(capture => capture.Value);
} }
} }
......
...@@ -2,9 +2,18 @@ using System; ...@@ -2,9 +2,18 @@ using System;
namespace PcapDotNet.Base namespace PcapDotNet.Base
{ {
/// <summary>
/// Extension method for UInt structure.
/// </summary>
public static class UIntExtensions public static class UIntExtensions
{ {
public static int NumDigits(this uint value, double digitsBase) /// <summary>
/// Returns the number of digits the number will be represented by according to a specific base.
/// </summary>
/// <param name="value">The number to check for number of digits.</param>
/// <param name="digitsBase">The base of the digits.</param>
/// <returns>The number of digits the number will be represented by according to a specific base.</returns>
public static int DigitsCount(this uint value, double digitsBase)
{ {
return (int)(Math.Floor(Math.Log(value, digitsBase)) + 1); return (int)(Math.Floor(Math.Log(value, digitsBase)) + 1);
} }
......
...@@ -167,7 +167,7 @@ namespace PcapDotNet.Core.Test ...@@ -167,7 +167,7 @@ namespace PcapDotNet.Core.Test
// Break loop // Break loop
TestReceivePackets(NumPacketsToSend, NumPacketsToSend, 0, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, 0, 0, 0.027); TestReceivePackets(NumPacketsToSend, NumPacketsToSend, 0, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, 0, 0, 0.027);
TestReceivePackets(NumPacketsToSend, NumPacketsToSend, NumPacketsToSend / 2, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, NumPacketsToSend / 2, 0, 0.032); TestReceivePackets(NumPacketsToSend, NumPacketsToSend, NumPacketsToSend / 2, 2, PacketSize, PacketCommunicatorReceiveResult.BreakLoop, NumPacketsToSend / 2, 0, 0.045);
} }
[TestMethod] [TestMethod]
......
...@@ -35,7 +35,7 @@ namespace PcapDotNet.Packets.Http ...@@ -35,7 +35,7 @@ namespace PcapDotNet.Packets.Http
if (StatusCode == null) if (StatusCode == null)
return length; return length;
length += StatusCode.Value.NumDigits(10) + 1; length += StatusCode.Value.DigitsCount(10) + 1;
if (ReasonPhrase == null) if (ReasonPhrase == null)
return length; return length;
......
...@@ -36,7 +36,7 @@ namespace PcapDotNet.Packets.Http ...@@ -36,7 +36,7 @@ namespace PcapDotNet.Packets.Http
private void SetTransferCodings(IList<string> transferCodings) private void SetTransferCodings(IList<string> transferCodings)
{ {
if (transferCodings.Any(coding => coding.Any(c => c.IsUpperCaseAlpha()))) if (transferCodings.Any(coding => coding.Any(c => c.IsUppercaseAlpha())))
_transferCodings = transferCodings.Select(coding => coding.ToLowerInvariant()).ToArray().AsReadOnly(); _transferCodings = transferCodings.Select(coding => coding.ToLowerInvariant()).ToArray().AsReadOnly();
else else
_transferCodings = transferCodings.AsReadOnly(); _transferCodings = transferCodings.AsReadOnly();
......
...@@ -20,7 +20,7 @@ namespace PcapDotNet.Packets.Http ...@@ -20,7 +20,7 @@ namespace PcapDotNet.Packets.Http
public int Length public int Length
{ {
get { return _httpSlashBytes.Length + Major.NumDigits(10) + 1 + Minor.NumDigits(10); } get { return _httpSlashBytes.Length + Major.DigitsCount(10) + 1 + Minor.DigitsCount(10); }
} }
public override string ToString() public override string ToString()
......
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