/// <summary> /// Check that the expected Encoding is mapped from the given IETF charset id, /// as are used in the LanguageBaseList Attribute. /// </summary> private void DoTest(Encoding expectedEncoding, ushort ietfCharsetId) { LanguageBaseItem item = new LanguageBaseItem(/*"en"*/ Data_LanguageBaseList.LangEn, ietfCharsetId, (ServiceAttributeId)0x0100); Encoding encResult = item.GetEncoding(); Assert.AreEqual(expectedEncoding, encResult); }
/// <summary> /// Get the value of the <see cref="F:InTheHand.Net.Bluetooth.ElementTypeDescriptor.TextString"/>, /// when it is encoded as specified by the given IETF Charset identifer. /// </summary> /// - /// <remarks> /// Note that a strict decoding of the string is carried out /// (except on the NETCF where it is not supported). /// Thus if the value is not in the specified encoding, or has been /// encoded incorrectly, then an error will occur. /// </remarks> /// - /// <returns> /// A <see cref="T:System.String"/> holding the value of the /// <see cref="F:InTheHand.Net.Bluetooth.ElementTypeDescriptor.TextString"/> /// from the service element. /// </returns> /// - /// <exception cref="T:System.InvalidOperationException"> /// The service element is not of type /// <see cref="F:InTheHand.Net.Bluetooth.ElementTypeDescriptor.TextString"/>. /// </exception> /// <exception cref="T:System.Text.DecoderFallbackException"> /// If the value in the service element is not a valid string in the given encoding. /// </exception> public String GetValueAsString(LanguageBaseItem languageBase) { if (languageBase == null) { throw new ArgumentNullException("languageBase"); } Encoding enc = languageBase.GetEncoding(); if (_strictStringDecoding) { enc = (Encoding)enc.Clone(); //not in NETCFv1 enc.DecoderFallback = new DecoderExceptionFallback(); // not in NETCF. // Not intended for encoding, but set it anyway. enc.EncoderFallback = new EncoderExceptionFallback(); // not in NETCF. } return(GetValueAsString(enc)); }