Interface implementation in f #

Here is my C # interface:

public interface ITemplateService { string RenderTemplate(object model, string templateName); string RenderTemplate(object model, string templateName, string directory); } 

I am trying to execute an implementation in F #, but got an error with the end keyword. (unexpected end in implementation file)

 module TemplateService open DotLiquid type TemplateService = inherit ITemplateService member this.RenderTemplate model (templateName:string):string = "" member this.RenderTemplate model (templateName:string, directory:string):string = "" end//error here. 

ps. What is this code in F #:

 Template template = Template.Parse(stringToTemplate); template.Render(Hash.FromAnonymousObject(model)); 
+4
source share
2 answers

In addition to ChaosPandion's answer:

A class can be defined as follows:

 type ClassName(constructorArguments) = class ... end 

or like this:

 type ClassName(constructorArguments) = ... 

Thus, you need either the class and end , or none of them. Usually people use a form without class and end .

Your other piece of code will look something like this:

 let template = Template.Parse stringToTemplate template.Render (Hash.FromAnonymousObject model) 
+3
source

Since you are implementing an interface, you will want to use this syntax.

 type TemplateService() = interface ITemplateService with member this.RenderTemplate model (templateName:string):string = "" member this.RenderTemplate model (templateName:string, directory:string):string = "" 
+4
source

Source: https://habr.com/ru/post/1343713/


All Articles