FSharp · Script
open System
[<AttributeUsage(AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)>]
type ReturnParameterDescriptionAttribute(info:string) =
inherit Attribute()
member x.Info = info
type HelloSimple =
static member Format name :
[<ReturnParameterDescription("A string containing 'Hello <name>!'.")>]
string =
"Hello " + name + "!"
type HelloTupleWithParentheses =
static member Format name :
[<ReturnParameterDescription("A string containing 'Hello <name>!'.")>]
[<ReturnParameterDescription("A string containing 'Goodbye <name>!'.")>]
(string * string) =
("Hello " + name + "!", "Goodbye " + name + "!")
type HelloTupleWithoutParentheses =
static member Format name :
[<ReturnParameterDescription("A string containing 'Hello <name>!'.")>]
[<ReturnParameterDescription("A string containing 'Goodbye <name>!'.")>]
string * string =
("Hello " + name + "!", "Goodbye " + name + "!")
// Print the descriptions for each implementation.
[| typeof<HelloSimple>; typeof<HelloTupleWithParentheses>; typeof<HelloTupleWithoutParentheses> |]
|> Array.map (fun t ->
printfn "--- %s ---" t.Name
t.GetMethod("Format").ReturnParameter.GetCustomAttributes(typeof<ReturnParameterDescriptionAttribute>, false)
|> Array.map (fun attr -> (attr :?> ReturnParameterDescriptionAttribute).Info |> printfn "%s")
)