'Inheritance of a .Net interface in C#: How to access base members

Inheritance of a .Net interface: How to access to base properties

I want to create my own category class inherited from Microsoft.Office.Interop.Outlook.Category interface but I am trying to access members of the base interface without success.

I tried base.Name and this.Name both give me:

Error 2 'object' does not contain a definition for 'Name'

Using VS 2013, .Net 4.5

Code:

using System;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace MyCategory
{
        public class MyCategory : Outlook.Category
    {
        private string colorName; 
        public string ColorName
        {
            get
            {
                return this.colorName;
            }
            set
            {
                //Name is a member of Outlook.Category
                //https://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.outlook.category_members.aspx
                this.colorName = base.Name;
                //
            }
        }

    }
}


Solution 1:[1]

So far I see on your code, you didn't implement interface. You're not inheriting from a class but following contract established by Outlook.Category interface. There is no "base" members here, you have to add members to your class.

If you put mouse cursor above Outlook.Category it should offer to implement it for you.

I recommend you to take a deeper look to how interfaces work on C#

Solution 2:[2]

You are mistaking implementing an interface with object inheritance. Even though they both use the same syntax, they are very different.

An interface is a contract to allow many different implementations of the same general methods and properties. It is a guarantee that the class you wrote supports certain actions. You have to write the implementations for interfaces. This allows others at a higher level to not care about the details of how something gets accomplished, yet it allows them to know it will get accomplished.

Object inheritance allows you to use a parent class's (non-private) stuff. It's really taking a parent class and adding more features. In fact, in Java, this is known as "extending" a class. Find a class that already implements the interface Outlook.Category and inherit from that class and then call base.Name(). Then you could override or extend any additional behavior that you need.

I'm not familiar with the Outlook namespace, but the CategoryClass seems to be a class that implements your interface. You could try inheriting from that.

Solution 3:[3]

What is it exactly that you are trying to do? Add a new category in Outlook? In that case, you simply need to access Outlook category storage (either the registry or the default store in the profile).

Take a look at the IPM.Configuration.CategoryList hidden message in the Calendar folder - you can see it using OutlookSpy (I am its author): go to the Calendar folder, click IMAPIFolder button on the OutlookSpy ribbon, go to the "Associated Contents" tab, find the message with PR_MESSAGE_CLASS property = "IPM.Configuration.CategoryList", double click on it. The data will be in the PR_ROAMING_XMLSTREAM property. That hidden message can be accessed using MAPIFolder.GetStorage in the Outlook Object Model.

You can also use Redemption (I am also its author) to add a new category - see the RDOCategories object. Something like the following will do the job (VBA):

 set vSession = CreateObject("Redemption.RDOSession")
 vSession.MAPIOBJECT = Application.Session.MAPIOBJECT
 set vStore = vSession.Stores.DefaultStore
 set vCategories = vStore.Categories
 set vCategory = vCategories.Add("Redemption Category", olCategoryColorPeach)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Claudio Redi
Solution 2 ryanyuyu
Solution 3