F# Inherit from C# class + access protected fields

后端 未结 2 945
轻奢々
轻奢々 2021-01-21 08:02

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 t

相关标签:
2条回答
  • 2021-01-21 08:43

    See related questions:

    • F# - How to access protected member

    • Why isn't there a protected access modifier in F#?

    Basically I think you can't do it from within a let because it's actually in the context of an implicit lambda.

    0 讨论(0)
  • 2021-01-21 08:51

    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
    
    0 讨论(0)
提交回复
热议问题