Workaround Eiffel .NET limitations

There are a few limitations in the integration between Eiffel .NET and .NET solution. However, it is sometime possible to find workaround, a common technique is to use a C# facade project, and use it from the Eiffel .NET project.

See in the following section, a way to use a facade C# project to workaround the current limitation on ".NET generic" compilation (i.e the fact the Eiffel compiler does not support yet the .NET generics).

This technique can be adapted to bypass other limitations or annoyances.

Using generic .NET classes through a facade

Currently, Eiffel does not support consuming generics from C# classes. This tutorial demonstrates a workaround for this limitation by creating a Facade for a List<string> in C#

Creating a facade for the List type

A Facade simplifies access to complex components. In this case, we will create a Facade to manage a list of strings. The Facade will encapsulate the list's functionality and expose a more straightforward interface. Here's how you can do it:

using System.Collections; namespace ListOfString; /// <summary> /// Facade for a List<string> that encapsulates the list's functionality and exposes a few methods /// </summary> public class ListOfString { // Private list of strings private List<string> _list; // Constructor that initialize the list public ListOfString() { _list = new List<string>(); } // Add an item to the list public void Add(string item) { _list.Add(item); } // Check if the list contains a specific item public bool Contains(string item) { return _list.Contains(item); } // Remove a specific item from the list public void Remove(string item) { _list.Remove(item); } public IList GetList() { return _list.ToList(); } }

Creating a C# library

To consume the Facade in Eiffel, we need to create a C# library. I recommend following the tutorial on creating a class library with C# and .NET on Microsoft’s official site. You can access it here. This tutorial guides you through the process of creating a class library using C# and .NET.

Consuming the C# library from Eiffel

Finally, we need to consume the C# library from Eiffel.

Open the Eiffel configuration file (.ecf) of your project and add the following entry

<assembly name="ListOfString" location="$PATH_CS_LIB\ListOfString.dll"/>

Conclusion

By creating a Facade for a List<string> in C#, we can effectively consume C# generic features in Eiffel. Obviously, this approach can be extended to other generic types as well.