I have this base class that creates a new SQL Server connection and does some utility methods in C#, I want to inherit in F#. Currently I cannot access the protected fields in the C# class from F#, although this would work in C#.
C# abstract class
public abstract class SQL
{
protected readonly SqlConnectionStringBuilder bld;
protected readonly SqlCommand cmd;
protected readonly SqlConnection conn;
protected readonly string connstring;
protected string userid;
public SQL(string server, string db)
{
bld = new SqlConnectionStringBuilder();
bld.DataSource = server;
bld.InitialCatalog = db;
bld.IntegratedSecurity = true;
connstring = bld.ConnectionString;
conn = new SqlConnection(connstring);
cmd = new SqlCommand();
GetUserID();
//Other utility methods here
}
F# code to inherit
type Transfer ( server : string ) ( db : string ) =
inherit SQL(server, db)
let accessAbstractConn = conn. //Can't access protected field????
Have I missed something here? I have tried aliasing the base class field e.g. this.conn which also does not work.
Thanks Richard
You can add a self-identifier to the constructor:
type Transfer ( server : string, db : string ) as this =
inherit SQL(server, db)
let accessAbstractConn = this.conn
or, use the base
keyword:
type Transfer ( server : string, db : string ) =
inherit SQL(server, db)
let accessAbstractConn = base.conn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With