MimeKit.TextPart.SetText C# (CSharp) Method

SetText() public method

Sets the text content and the charset parameter in the Content-Type header.
This method is similar to setting the TextPart.Text property, but allows specifying a charset encoding to use. Also updates the ContentType.Charset property.
/// is null. /// -or- /// is null. ///
public SetText ( Portable.Text.Encoding encoding, string text ) : void
encoding Portable.Text.Encoding The charset encoding.
text string The text content.
return void
		public void SetText (Encoding encoding, string text)
		{
			if (encoding == null)
				throw new ArgumentNullException ("encoding");

			if (text == null)
				throw new ArgumentNullException ("text");

			ContentType.Parameters["charset"] = CharsetUtils.GetMimeCharset (encoding);
			var content = new MemoryStream (encoding.GetBytes (text));
			ContentObject = new ContentObject (content);
		}

Same methods

TextPart::SetText ( string charset, string text ) : void

Usage Example

コード例 #1
0
ファイル: TextPartTests.cs プロジェクト: jstedfast/MimeKit
		public void TestArgumentExceptions ()
		{
			var text = new TextPart (TextFormat.Plain);

			Assert.Throws<ArgumentNullException> (() => new TextPart ("plain", (object[]) null));
			Assert.Throws<ArgumentException> (() => new TextPart ("plain", Encoding.UTF8, "blah blah blah", Encoding.UTF8));
			Assert.Throws<ArgumentException> (() => new TextPart ("plain", Encoding.UTF8, "blah blah blah", "blah blah"));
			Assert.Throws<ArgumentException> (() => new TextPart ("plain", 5));
			Assert.Throws<ArgumentOutOfRangeException> (() => new TextPart ((TextFormat) 500));

			Assert.Throws<ArgumentNullException> (() => text.Accept (null));
			Assert.Throws<ArgumentNullException> (() => text.GetText ((string) null));
			Assert.Throws<ArgumentNullException> (() => text.GetText ((Encoding) null));
			Assert.Throws<ArgumentNullException> (() => text.SetText ((string) null, "text"));
			Assert.Throws<ArgumentNullException> (() => text.SetText ((Encoding) null, "text"));
			Assert.Throws<ArgumentNullException> (() => text.SetText ("iso-8859-1", null));
			Assert.Throws<ArgumentNullException> (() => text.SetText (Encoding.UTF8, null));
		}
All Usage Examples Of MimeKit.TextPart::SetText