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;
//
}
}
}
}
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 callbase.Name()
. Then you could override or extend any additional behavior that you need.I'm not familiar with the
Outlook
namespace, but theCategoryClass
seems to be a class that implements your interface. You could try inheriting from that.