首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VSTO Outlook 2021 Reminder.Item对象类型

VSTO Outlook 2021 Reminder.Item对象类型
EN

Stack Overflow用户
提问于 2022-04-15 21:25:15
回答 2查看 77关注 0票数 0

我正在尝试替换默认的提醒对话框。作为其中的一部分,我想访问更多关于提醒放置在新对话框中的条目的信息。我见过一些旧的例子(Office 2013左右),在这些例子中,探测Reminder.Item的类型似乎很有效。但是,在VS 2022中的Outlook2021/ VSTO中,即使我知道的项是MeetingItems,if语句也会失效。

当我停止和调试时,我可以让intellisense打开动态视图,并且我可以告诉它是一个MeetingItem (有一个主题、类别、组织者等)。但类型只是COM对象。此外,如果使用即时窗口强制转换为MeetingItem,则会得到以下错误:(r.Item as Outlook.MeetingItem).Categories error CS0433:类型'MeetingItem‘同时存在于'Microsoft.Office.Interop.Outlook、Version=15.0.0.0、Culture=neutral、PublicKeyToken=71e9bce111e9429c’和‘任务、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null’中。

这是一个新的VSTO Outlook项目,我所做的就是添加下面的代码(我从我的另一个项目中复制,以确保它不是项目的问题)。我没有添加任何引用,而且项目本身也没有引用。我假设,如果您创建一个VSTO Outlook AddIn,然后添加此代码,则会出现相同的问题。

对这里发生了什么有什么想法吗?为什么我不能访问Reminder.Item,为什么VS认为除了Office之外,MeetingItem还存在于我的项目中?

使用Outlook = Microsoft.Office.Interop.Outlook;使用Office =Microsoft.Office.Core

命名空间任务{公共部分类ThisAddIn {私有Outlook.Reminders m_Reminders;

代码语言:javascript
复制
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        m_Reminders = Application.Reminders;
        m_Reminders.BeforeReminderShow += Reminders_BeforeReminderShow;
    }

    private void Reminders_BeforeReminderShow(ref bool Cancel)
    {
        foreach (Outlook.Reminder r in m_Reminders)
        {
            if (r.IsVisible)
            {
                if (r.Item is Outlook.AppointmentItem)
                {
                    Console.WriteLine("item is an appointment");
                }
                else if (r.Item is Outlook.MeetingItem)
                {
                    Console.WriteLine("item is a meeting");
                }
            }
        }
    }
EN

回答 2

Stack Overflow用户

发布于 2022-04-15 23:26:03

使用后期绑定从Reminder.Item访问Reminder.Item属性(所有OOM对象都公开它),以确定项类型。请注意,您还可以拥有TaskItem和常规MailItem对象。

票数 0
EN

Stack Overflow用户

发布于 2022-04-16 19:47:52

你的代码是有效的。但是,我注意到以下错误与在运行时转换Outlook对象无关:

代码语言:javascript
复制
(r.Item as Outlook.MeetingItem).Categories error CS0433: The type 'MeetingItem' exists in both 'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' and 'Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'

看起来互操作类型也嵌入到Tasks程序集中。您需要显式地声明将使用什么类型(它来自何处),或者只是不要将互操作类型嵌入到其他程序集中,以避免在不同的程序集中具有等效的类型。

阅读编译器错误CS0433文章中有关错误的更多信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71889086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档