I want to have a constructor that is blank and a constructor overload that accepts a parameter and assign it to a public property.
This is where I am stuck:
type TemplateService() =
interface ITemplateService with
//Properties
member TemplateDirectory = ""
//Constructors
new (templateDirectory:string) = //Error here.
if (templateDirectory == null) then
raise (new System.ArgumentNullException("templateDirectory"))
TemplateDirectory = templateDirectory;
It gives me the error: `Unexpected keyword 'new' in the Object expression. Expected 'member', 'override' or other token.
If I use member, the property TemplateDirectory gives this error:
This instance member needs a parameter to represent the object being invoked. Make the member static or use the notation 'member x.Member(args) = ...'
You could try this.
type TemplateService(templateDirectory : string) =
do
if templateDirectory = null then nullArg "templateDirectory"
new() = TemplateService("")
interface ITemplateService with
member this.TemplateDirectory = templateDirectory
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