« Revised FFT Core for Iridium | Main | Strange PowerShell Bug? »
Tuesday
09Jan2007

C++/CLI: Explicitly Implement Interface Properties

In case you ever wondered how to explicitly implement interface properties in C++/CLI that collide with an already existing better typed property: It’s quite easy, but I didn’t find a sample in neither the language specification nor the web.

Imagine you have some already existing generic ItemBuilder class:

ref class Item;

generic<class T>
where T : Item
public ref class ItemBuilder
{
public:
    property T Prototype { T 
get()};
};

But now you want to generalize it, to be able to access the prototype property as Item, independent of the actual generic class type. So you define an interface IItemBuilder:

public interface class IItemBuilder
{
    property Item^ Prototype { Item^ 
get()};
};

How to explicitly implement this interface in ItemBuilder in C++/CLI?

generic<class T>
where T : Item
public ref class ItemBuilder : public IPacketBuilder
{
private:
    
virtual property Item^ PrototypeUntyped
        { Item^ 
get() sealed = IItemBuilder::Prototype::get; };
public
:
    property T Prototype { T 
get()};
}

Let me know if you know a better approach …

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.