簡體   English   中英

Outlook COM Interop 方法事件名稱沖突

[英]Outlook COM Interop method event name conflict

我正在使用 Outlook com 界面來自動創建電子郵件。 我正在嘗試處理MailItem.Close事件,但問題是 MailItem 也有一個MailItem.Close()方法。 我希望編譯器會推斷出我指的是該事件,因為我試圖將委托附加到它,但事實並非如此。

private void editButton_Click(object sender, RoutedEventArgs e)
{
    outlook.MailItem editItem;
    ...
    editItem.Close += delegate { editItem_onClose(editItem); };
    ...
}

實際錯誤是:
Error 4 Cannot assign to 'Close' because it is a 'method group'

警告是:
Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Outlook._MailItem.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose)' and non-method 'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Close'. Using method group.

編輯:

我的Microsoft.Office.Interop.Outlook命名空間沒有ItemEvents_10_Event接口。 我有outlook.ItemEvents_10_SinkHelperoutlook.ItemEvents_10我試圖像這樣投射到outlook.ItemEvents_10

var events = (outlook.ItemEvents_10)editItem;
events.Close += delegate { editItem_AfterWrite(editItem, editRow); };

但我仍然收到“events.Close 是一個方法組”錯誤。

您需要將郵件項目對象轉換為提供事件或方法的正確接口或類。 ItemEvents_10_Event接口提供 Close 事件,MailItem 類提供 Close 方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM