當前位置: 首頁>>代碼示例>>C#>>正文


C# MimeMessage.GetType方法代碼示例

本文整理匯總了C#中MimeKit.MimeMessage.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# MimeMessage.GetType方法的具體用法?C# MimeMessage.GetType怎麽用?C# MimeMessage.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MimeKit.MimeMessage的用法示例。


在下文中一共展示了MimeMessage.GetType方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestChangeHeaders

		public void TestChangeHeaders ()
		{
			const string addressList1 = "\"Example 1\" <[email protected]>, \"Example 2\" <[email protected]>";
			const string addressList2 = "\"Example 3\" <[email protected]>, \"Example 4\" <[email protected]>";
			const string references1 = "<[email protected]> <[email protected]>";
			const string references2 = "<[email protected]> <[email protected]>";
			const string mailbox1 = "\"Example 1\" <[email protected]>";
			const string mailbox2 = "\"Example 2\" <[email protected]>";
			const string date1 = "Thu, 28 Jun 2007 12:47:52 -0500";
			const string date2 = "Fri, 29 Jun 2007 12:47:52 -0500";
			const string msgid1 = "[email protected]";
			const string msgid2 = "[email protected]";
			var message = new MimeMessage ();

			foreach (var property in message.GetType ().GetProperties (BindingFlags.Instance | BindingFlags.Public)) {
				var getter = property.GetGetMethod ();
				var setter = property.GetSetMethod ();
				DateTimeOffset date;
				object value;
				HeaderId id;

				if (!Enum.TryParse (property.Name, out id))
					continue;

				switch (property.PropertyType.FullName) {
				case "MimeKit.InternetAddressList":
					message.Headers[id] = addressList1;

					value = getter.Invoke (message, new object[0]);
					Assert.AreEqual (addressList1, value.ToString (), "Unexpected result when setting {0} to addressList1", property.Name);

					message.Headers[message.Headers.IndexOf (id)] = new Header (id, addressList2);

					value = getter.Invoke (message, new object[0]);
					Assert.AreEqual (addressList2, value.ToString (), "Unexpected result when setting {0} to addressList2", property.Name);
					break;
				case "MimeKit.MailboxAddress":
					message.Headers[id] = mailbox1;

					value = getter.Invoke (message, new object[0]);
					Assert.AreEqual (mailbox1, value.ToString (), "Unexpected result when setting {0} to mailbox1", property.Name);

					message.Headers[message.Headers.IndexOf (id)] = new Header (id, mailbox2);

					value = getter.Invoke (message, new object[0]);
					Assert.AreEqual (mailbox2, value.ToString (), "Unexpected result when setting {0} to mailbox2", property.Name);

					setter.Invoke (message, new object[] { null });
					value = getter.Invoke (message, new object[0]);
					Assert.IsNull (value, "Expected null value after setting {0} to null.", property.Name);
					Assert.AreEqual (-1, message.Headers.IndexOf (id), "Expected {0} header to be removed after setting it to null.", property.Name);
					break;
				case "MimeKit.MessageIdList":
					message.Headers[id] = references1;

					value = getter.Invoke (message, new object[0]);
					Assert.AreEqual (references1, value.ToString (), "Unexpected result when setting {0} to references1", property.Name);

					message.Headers[message.Headers.IndexOf (id)] = new Header (id, references2);

					value = getter.Invoke (message, new object[0]);
					Assert.AreEqual (references2, value.ToString (), "Unexpected result when setting {0} to references2", property.Name);
					break;
				case "System.DateTimeOffset":
					message.Headers[id] = date1;

					date = (DateTimeOffset) getter.Invoke (message, new object[0]);
					Assert.AreEqual (date1, DateUtils.FormatDate (date), "Unexpected result when setting {0} to date1", property.Name);

					message.Headers[message.Headers.IndexOf (id)] = new Header (id, date2);

					date = (DateTimeOffset) getter.Invoke (message, new object[0]);
					Assert.AreEqual (date2, DateUtils.FormatDate (date), "Unexpected result when setting {0} to date2", property.Name);
					break;
				case "System.String":
					switch (id) {
					case HeaderId.ResentMessageId:
					case HeaderId.MessageId:
					case HeaderId.InReplyTo:
						message.Headers[id] = "<" + msgid1 + ">";

						value = getter.Invoke (message, new object[0]);
						Assert.AreEqual (msgid1, value.ToString (), "Unexpected result when setting {0} to msgid1", property.Name);

						message.Headers[message.Headers.IndexOf (id)] = new Header (id, "<" + msgid2 + ">");

						value = getter.Invoke (message, new object[0]);
						Assert.AreEqual (msgid2, value.ToString (), "Unexpected result when setting {0} to msgid2", property.Name);

						setter.Invoke (message, new object[] { "<" + msgid1 + ">" });
						value = getter.Invoke (message, new object[0]);
						Assert.AreEqual (msgid1, value.ToString (), "Unexpected result when setting {0} to msgid1 via the setter.", property.Name);

						if (id == HeaderId.InReplyTo) {
							setter.Invoke (message, new object[] { null });
							value = getter.Invoke (message, new object[0]);
							Assert.IsNull (value, "Expected null value after setting {0} to null.", property.Name);
							Assert.AreEqual (-1, message.Headers.IndexOf (id), "Expected {0} header to be removed after setting it to null.", property.Name);
						}
						break;
//.........這裏部分代碼省略.........
開發者ID:dcga,項目名稱:MimeKit,代碼行數:101,代碼來源:MimeMessageTests.cs


注:本文中的MimeKit.MimeMessage.GetType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。