How can I get member variable class(int) from object Item in the below function? I can see it in Visual Studio debugger dynamic view. but not sure how could I access this programmatically.
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Application.ItemSend = new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
void Application_ItemSend(object Item, ref bool Cancel)
I want to use something like (int)Item.class So I can see Item's class such as mailitem, taskitem or meetingitem. and process accordingly.
CodePudding user response:
You can use standard .net ways of checking the item type at runtime, for example:
if (Item is Outlook.MailItem)
{
Outlook.MailItem mailItem =
(Item as Outlook.MailItem);
itemMessage = "The item is an e-mail message."
" The subject is " mailItem.Subject ".";
mailItem.Display(false);
}
else if (Item is Outlook.ContactItem)
{
Outlook.ContactItem contactItem =
(Item as Outlook.ContactItem);
itemMessage = "The item is a contact."
" The full name is " contactItem.Subject ".";
contactItem.Display(false);
}
else if (Item is Outlook.AppointmentItem)
{
Outlook.AppointmentItem apptItem =
(Item as Outlook.AppointmentItem);
itemMessage = "The item is an appointment."
" The subject is " apptItem.Subject ".";
}
else if (Item is Outlook.TaskItem)
{
Outlook.TaskItem taskItem =
(Item as Outlook.TaskItem);
itemMessage = "The item is a task. The body is "
taskItem.Body ".";
}
else if (Item is Outlook.MeetingItem)
{
Outlook.MeetingItem meetingItem =
(Item as Outlook.MeetingItem);
itemMessage = "The item is a meeting item. "
"The subject is " meetingItem.Subject ".";
}
See How to: Programmatically determine the current Outlook item for more information.
CodePudding user response:
Either use the Class
property (it is exposed by all OOM objects) - it will be 43 (OlObjectClass.olMail
) for the MailItem
objects, or use "is" and/or "as" operators.