fsprojects / FSharp.Compiler.CodeDom

An F# CodeDOM implementation (based on the old F# Power Pack)
http://fsprojects.github.io/FSharp.Compiler.CodeDom/
The Unlicense
25 stars 14 forks source link

Option types #19

Closed tonyroberts closed 7 years ago

tonyroberts commented 7 years ago

Is it possible to declare parameters as option types?

For example, when creating a method like this:

var method = CodeMemberMethod {
    Name = "Test",
    ReturnType = new CodeTypeReference(typeof(string))
};
var parameter = new CodeParameterDeclarationExpression(typeof(FSharpOption<string>), "x");
method.Parameters.Add(param);

the generated code looks something like

            abstract Invoke : Microsoft.FSharp.Core.FSharpOption<string> -> string
            default this.Invoke  (fund:Microsoft.FSharp.Core.FSharpOption<string>) =

but I would like to be able to use the f# Option type, e.g.

            abstract Invoke : Option<string> -> string
            default this.Invoke  (fund:Option<string>) =

It looks like generateTypeRef or getTypeRef could be modified to map FSharpOption<> to Option<> when outputting the F# code, but is that the right thing to do or is there another way?

thanks! Tony