0

I'm trying to create a class implementing the EA.Element interface of the Interop.EA.dll provided by Sparx Systems.

The reason I want to provide my own implementation of the Sparx API element is because the API is terribly slow to use. I found a faster way (for read-only) by getting the data from the database directly, which would suit my needs in 90% of the cases.

If I could simply provide my own implementation of that interop interface, I could leave all of my existing code alone.

So I created the class like this:

namespace TSF.UmlToolingFramework.Wrappers.EA
{
    internal class EADBElementWrapper : global::EA.Element
    {
    }
}

and then use the Implement Interface feature of Visual Studio to let VS create all the methods and properties.

Worked like a charm, except for MiscData.
Visual Studio created

public string MiscData => throw new NotImplementedException();

But when trying to compile I still get the error

CS0535 'EADBElementWrapper' does not implement interface member 'IDualElement.MiscData[int].get'

Looking in the object browser the original MiscData property is listed as follows:

  • MiscData[int]
    string MiscData {get;}

enter image description here

I tried a few variations, like string[] or MiscData[int] but none of those seemed to help.

How can I implement this property in my class?

Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50

1 Answers1

0

Check out Is named indexer property possible? answer. It looks like you are trying to do something which should not/can not be done.

MiscData[int] should represent an indexer property which are unnamed from C# point of view, you can try using IndexerNameAttribute but not sure if it will satisfy the requirement:

class EADBElementWrapper
{
    [IndexerName("MiscData")]
    public string this[int i]
    {
        get => throw new NotImplementedException();
    }
}
Guru Stron
  • 102,774
  • 10
  • 95
  • 132
  • Thanks for you answer. Unfortunately I still have the same error when trying to compile, so it must be something else. – Geert Bellekens May 22 '23 at 07:11
  • @GeertBellekens have you checked the first link? From the first answer - _"No - you can't write named indexers in C#. As of C# 4 you can consume them for COM objects, but you can't write them."_ Are you sure you need to implement the interface and not just use existing implementations? – Guru Stron May 22 '23 at 07:13
  • I'm trying to replace the existing implementation from Sparx with my own version. The reason I want to implement the interface is because I have a whole framework based on these interfaces. It would be so much easier to provide my own implementation of the interface instead of replacing all the references throughout my code. But if it's not possible, I guess I have no other choice. – Geert Bellekens May 22 '23 at 07:54