The previous C# class I posted about a year ago had some issues and bugs. Vyacheslav Shevelyov, who reported a few of these issues, took upon himself to write a new C# class for the EPANET Toolkit. From the class readme file:
This archive contains C# source code to interact with unmanaged EPANET 2 hydraulics library and example files to demonstrate/test core functionality. Sources written for epanet2.dll codeversion 20012. There are no CLI classes, that wrap EPANET object, just plain function imports and constants.
Only UnsafeNativeMethods.cs, Enumerations.cs and optionally EpanetException.cs should be used to call epanet2.dll from C# code:
- UnsafeNativeMethods.cs contains UnsafeNativeMethods class with EPANET function declarations as well as some important constants.
- Enumerations.cs file contains EPANET constant end defines, grouped in several enums.
- EpanetException.cs is mapper of error codes, returned by Epanet to CLI exceptions. It is not required to call EPANET functions, but may be useful due to all EPANET functions return error codes to indicate errors.
Other files are examples, to demonstrate code functionality and make some
The code is distributed under the unlicense license.
Here are a few code snippets just to show the function calls and Enums:
UnsafeNativeMethods.ENgetcount(CountType.Node, out nodeCount); UnsafeNativeMethods.ENgetnodevalue(i, NodeValue.Head, out value); UnsafeNativeMethods.ENgetlinkvalue(i, LinkValue.Flow, out value);
Download Epanet-c-sharp (zip).