문제

Here is my c# interface:

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

I'm trying to make an implementation in F# but got an error on the keyword end. (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));
도움이 되었습니까?

해결책

In addition to ChaosPandion's answer:

A class can either be defined like this:

type ClassName(constructorArguments) =
  class
    ...
  end

or like this:

type ClassName(constructorArguments) =
  ...

So you need either both the class and the end keyword or none of them. Usually people use the form without class and end.

Your other code snippet would look something like this:

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

다른 팁

Since you are implementing an interface you'll 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 = ""
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top