Example C# NET library
One advantage of the NET environment is that you can mix the compiled object
files from different languages to one program. To test this we use a small
class definition that is written in C#, compile it to a library and use this
to show how to access the parts of the class definition from within a HBasic
program.
C# program (library)
SInce this program has no entry point we will call it a library. Apart
from the missing entrypoint there are no other differences between a normal
program and a library.
You can find the sourcecode for this example in the code_examples/csharp
folder of yout HBasic directory. The example program is called
csharp_class_example.cs.
To create a compiled library from it compile it with the NET compiler with
cscc -shared -o FooBar.dll csharp_class_example.cs
or create a csharp project in HBasic, load the sourcecode and insert
-shared -o FooBar.dll
into compiler options of project.
using System;
namespace FooBar;
{
public class MyClass
{
/* Example of constructor method. */
public MyClass()
{
Console.WriteLine( "Constructor of MyClass" );
}
/* Const value. */
public const int MyConst = 12;
/* Field */
public int MyField = 34;
public int Field2 = 444;
/* Method. */
public int getval()
{
return( 1234 );
}
/* Property. */
public int MyProperty
{
get
{
return MyField;
}
set
{
MyField = value;
}
}
/* Event definition. */
public event EventHandler MyEvent;
/* Enum definition. */
public enum myenum
{
val1 = 3,
val2 = 8
}
}
}
Example FooBar.cs: C# class definition that should be
instantiated in HBasic.
After you have created the compiled library FooBar.dll you may include FooBar.dll
into your HBasic project with the package editor.