Thanks for Quora + Reflector + MSDN, I’ve figured out how to expose extension methods from F#

  1. Create a public module within a namespace
  2. Add the extension method as a function
  3. Decorate both the module and the function(s) with the ExtensionMethodAttribute

namespace Castle.MonoRail
 
[<System.Runtime.CompilerServices.ExtensionAttribute>]
module public ExtensionMethods = 
 
    open Castle.MonoRail.Routing
    open Castle.MonoRail.Hosting.Mvc
 
    [<System.Runtime.CompilerServices.ExtensionAttribute>]
    let Match(router:Router, path:string) = 
        router.Match(path, MonoRailHandlerMediator())

2 Comments

  1. Mauricio Scheffer says:

    Excellent, I just had to write some extension methods and used this as reference. The only downside to this is that it doesn’t support overloads. But if you use a type instead of a module and static members instead of let bindings, you can have overloaded extensions.

  2. hammett says:

    I’ve used [CompiledName] to support overloads..

Leave a Reply