本文整理汇总了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;
//.........这里部分代码省略.........