Commit 066e0511 authored by Brickner_cp's avatar Brickner_cp

DNS

parent fc7e1c71
......@@ -27,6 +27,7 @@
<SPACE_AFTER_TYPECAST_PARENTHESES>False</SPACE_AFTER_TYPECAST_PARENTHESES>
<SPACE_AROUND_MULTIPLICATIVE_OP>True</SPACE_AROUND_MULTIPLICATIVE_OP>
<SPACE_BEFORE_SIZEOF_PARENTHESES>False</SPACE_BEFORE_SIZEOF_PARENTHESES>
<SPACE_BEFORE_TYPEOF_PARENTHESES>False</SPACE_BEFORE_TYPEOF_PARENTHESES>
<WRAP_LIMIT>160</WRAP_LIMIT>
</FormatSettings>
<UsingsSettings />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace PcapDotNet.Base
{
/// <summary>
/// Extension methods for MemberInfo.
/// </summary>
public static class MemberInfoExtensions
{
/// <summary>
/// When overridden in a derived class, returns a sequence of custom attributes identified by System.Type.
/// </summary>
/// <typeparam name="T">TThe type of attribute to search for. Only attributes that are assignable to this type are returned.</typeparam>
/// <param name="memberInfo">The memberInfo to look the attributes on.</param>
/// <param name="inherit">Specifies whether to search this member's inheritance chain to find the attributes.</param>
/// <returns>A sequence of custom attributes applied to this member, or a sequence with zero (0) elements if no attributes have been applied.</returns>
public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo memberInfo, bool inherit) where T : Attribute
{
if (memberInfo == null)
throw new ArgumentNullException("memberInfo");
return memberInfo.GetCustomAttributes(typeof(T), inherit).Cast<T>();
}
}
}
\ No newline at end of file
......@@ -93,6 +93,7 @@
<Compile Include="IListExtensions.cs" />
<Compile Include="InlineEqualityComparer.cs" />
<Compile Include="MatchExtensions.cs" />
<Compile Include="MemberInfoExtensions.cs" />
<Compile Include="PropertyInfoExtensions.cs" />
<Compile Include="TimeSpanExtensions.cs" />
<Compile Include="TypeExtensions.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace PcapDotNet.Base
{
......@@ -19,24 +17,11 @@ namespace PcapDotNet.Base
}
}
/// <summary>
/// Extension methods for MemberInfo.
/// </summary>
public static class MemberInfoExtensions
public static class ObjectExtensions
{
/// <summary>
/// When overridden in a derived class, returns a sequence of custom attributes identified by System.Type.
/// </summary>
/// <typeparam name="T">TThe type of attribute to search for. Only attributes that are assignable to this type are returned.</typeparam>
/// <param name="memberInfo">The memberInfo to look the attributes on.</param>
/// <param name="inherit">Specifies whether to search this member's inheritance chain to find the attributes.</param>
/// <returns>A sequence of custom attributes applied to this member, or a sequence with zero (0) elements if no attributes have been applied.</returns>
public static IEnumerable<T> GetCustomAttributes<T>(this MemberInfo memberInfo, bool inherit) where T : Attribute
public static bool IsDefinedEnumValue<T>(this Object enumValue)
{
if (memberInfo == null)
throw new ArgumentNullException("memberInfo");
return memberInfo.GetCustomAttributes(typeof(T), inherit).Cast<T>();
return Enum.IsDefined(typeof(T), enumValue);
}
}
}
\ No newline at end of file
......@@ -264,12 +264,19 @@ namespace PcapDotNet.Packets.Dns
};
}
/*
protected override bool CalculateIsValid()
{
return Length >= HeaderBaseLength && Length == HeaderLength;
if (_isValid == null)
{
_isValid = Length >= HeaderLength &&
QueryCount == Queries.Count &&
AnswerCount == Answers.Count &&
AuthorityCount == Authorities.Count &&
AdditionalCount == Additionals.Count;
}
return _isValid.Value;
}
*/
internal DnsDatagram(byte[] buffer, int offset, int length)
: base(buffer, offset, length)
{
......@@ -397,7 +404,7 @@ namespace PcapDotNet.Packets.Dns
private delegate TRecord ParseRecord<out TRecord>(DnsDatagram dns, int offset, out int numBytesRead);
private void ParseRecords<TRecord>(int offset, Func<ushort> countDelegate, ParseRecord<TRecord> parseRecord,
ref ReadOnlyCollection<TRecord> parsedRecords, ref int nextOffset)
ref ReadOnlyCollection<TRecord> parsedRecords, ref int nextOffset) where TRecord : DnsResourceRecord
{
if (parsedRecords == null && Length >= offset)
{
......@@ -428,5 +435,7 @@ namespace PcapDotNet.Packets.Dns
private int _answersOffset;
private int _authoritiesOffset;
private int _additionalsOffset;
private bool? _isValid;
}
}
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