Updated wikipage Eiffel for .NET Integration. (Signed-off-by:jocelyn).

git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2430 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
eiffel-org
2023-10-02 10:26:30 +00:00
parent 7fe9407ccf
commit 6a641f9fa1

View File

@@ -1,4 +1,4 @@
[[Property:modification_date|Mon, 02 Oct 2023 10:20:43 GMT]]
[[Property:modification_date|Mon, 02 Oct 2023 10:26:30 GMT]]
[[Property:publication_date|Wed, 27 Sep 2023 19:33:07 GMT]]
[[Property:title|Eiffel for .NET Integration]]
[[Property:weight|3]]
@@ -59,64 +59,7 @@ As noted above, Eiffel for .NET fully supports the powerful genericity mechanism
* If you want to use a generic .NET class (for example in C#), you have to use special techniques as described next.
===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:
<code lang="cs">
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<string> _list;
public ListOfString()
{
_list = new List<string>();
}
public void Add(string item)
{
_list.Add(item);
}
public bool Contains(string item)
{
return _list.Contains(item);
}
public void Remove(string item)
{
_list.Remove(item);
}
public IList GetList()
{
return _list.ToList();
}
}
</code>
====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 Microsofts official site. You can access it [https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?pivots=dotnet-7-0 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
<code><assembly name="ListOfString" location="$PATH_CS_LIB\ListOfString.dll"/></code>
====Conclusion====
By creating a Facade for a `List<string>` in C#, we can effectively consume C# generic features in Eiffel.
This approach can be extended to other generic types as well.
{{info: Read the [[Workaround Eiffel .NET limitations]] page to learn how to workaround such limitation. }}
===Enum types===
Eiffel for .NET supports .NET enum types implicitly. From the point of view of Eiffel, they are just considered as expanded classes. The only difference is in the code generation. Eiffel for .NET cannot declare new enum types yet.