예제 #1
0
 private static Dictionary <IcmpMessageType, IcmpDatagram> InitializeComplexOptions()
 {
     return(Enumerable.ToDictionary(Enumerable.Select(Enumerable.Select(Enumerable.Where <Type>((IEnumerable <Type>)Assembly.GetExecutingAssembly().GetTypes(), (Func <Type, bool>)(type =>
     {
         if (typeof(IcmpDatagram).IsAssignableFrom(type))
         {
             return IcmpDatagramFactory.GetRegistrationAttribute(type) != null;
         }
         return false;
     })), type => new
     {
         type = type,
         constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, (Binder)null, new Type[3]
         {
             typeof(byte[]),
             typeof(int),
             typeof(int)
         }, (ParameterModifier[])null)
     }), param0 => new
     {
         MessageType = IcmpDatagramFactory.GetRegistrationAttribute(param0.type).MessageType,
         Datagram = (IcmpDatagram)param0.constructor.Invoke(new object[3]
         {
             null,
             (object)0,
             (object)0
         })
     }), prototype => prototype.MessageType, prototype => prototype.Datagram));
 }
예제 #2
0
 public static IcmpDatagram CreateDatagram(byte[] buffer, int offset, int length)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (length <= 0)
     {
         return((IcmpDatagram) new IcmpUnknownDatagram(buffer, offset, length));
     }
     return(IcmpDatagramFactory.CreateInstance((IcmpMessageType)buffer[offset], buffer, offset, length));
 }