/// <summary> /// Convert a StunMethodClass to an host-byte ordered unsigned short /// </summary> /// <param name="mClass">The StunMethodClass to convert</param> /// <returns> /// The unsigned short (16bits) matching the StunMethodClass /// Return max UInt16 value if the mClass parameter is StunMethodClass.Unmanaged /// </returns> public static UInt16 MethodClassToUInt16(StunMethodClass mClass) { foreach (FieldInfo field in typeof(StunMethodClass).GetFields()) { if (field.Name == mClass.ToString()) { Object[] fieldAttributes = field.GetCustomAttributes(typeof(StunValueAttribute), false); if (fieldAttributes.Length == 1) { StunValueAttribute stunValueAttribute = fieldAttributes.GetValue(0) as StunValueAttribute; return(stunValueAttribute.Value); } } } return(0xFFFF); }
/// <summary> /// Convert a StunMethodClass to an host-byte ordered unsigned short /// </summary> /// <param name="mClass">The StunMethodClass to convert</param> /// <returns> /// The unsigned short (16bits) matching the StunMethodClass /// Return max UInt16 value if the mClass parameter is StunMethodClass.Unmanaged /// </returns> public static UInt16 MethodClassToUInt16(StunMethodClass mClass) { foreach (FieldInfo field in typeof(StunMethodClass).GetFields()) { if (field.Name == mClass.ToString()) { Object[] fieldAttributes = field.GetCustomAttributes(typeof(StunValueAttribute), false); if (fieldAttributes.Length == 1) { StunValueAttribute stunValueAttribute = fieldAttributes.GetValue(0) as StunValueAttribute; return stunValueAttribute.Value; } } } return 0xFFFF; }
/// <summary> /// Construct a message with given type, class and transaction ID /// </summary> /// <param name="type">The type of the message</param> /// <param name="mclass">The class of the message</param> /// <param name="transactionId">The transaction ID of the message </param> public StunMessage(StunMethodType type, StunMethodClass mclass, byte[] transactionId) { this.MethodType = type; this.MethodClass = mclass; this.TransactionID = transactionId; }
/// <summary> /// Construct a message with given type, class and transaction ID /// </summary> /// <param name="type">The type of the message</param> /// <param name="mclass">The class of the message</param> /// <param name="transactionId">The transaction ID of the message </param> public StunMessage(StunMethodType type, StunMethodClass mclass, byte[] transactionId) { this.MethodType = type; this.MethodClass = mclass; this.TransactionID = transactionId; }