C#: Extending Outlook.(_)Application.
Posted by Kristof in C#, Programming, Visual StudioDoes not work.
Outlook.Application and Outlook._Application are both interfaces. And I want to use them as a class in my program (I don’t know how they made that work).
I wanted to extend Outlook.Application and add a simple method to create a new email. But that does not work since you have to implement a bunch of methods which I hardly understand.
Thank Microsoft for creating extension methods, so here is my solution:
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace SendToExtended
{
static class OutlookExtensions
{
///
/// Creates and returns an Microsoft Outlook MailItem
///
///
an instantiated Outlook application
/// A new MailItem object
public static Outlook.MailItem CreateMailItem(this Outlook.Application outlook)
{
if (outlook == null)
throw new ArgumentException("outlook parameter cannot be null");
return (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);
}
}
}

Entries (RSS)