Pages

Thursday, July 19, 2012

F# code snippet on codeplex

As we are improving the F# ecosystem, the snippet project is created on codeplex web, so our development progress is visible to everyone. The F# code snippet project hosts the F# snippet file which can be consumed by the F# snippet addon. Feel free to follow and/or leave comments. 


Wednesday, July 11, 2012

Type Provider Project Template

I believe a beard well lathered is half shaved. If I have to do the type provider every now and often, I'd better get this process automated. I already have the code snippet support add basic building blocks for type provider class, but i still need to add the API files and often need to use Alt+Arrow Up/Down to adjust the file orders in the project.

I need to find a way to get this sorted out automatically. The Type Provider template is a solution. It can generate the basic project skeleton with API source file, test script, and the backbone type provider source code. The following screen shot shows how it works when add the package. 




The type provider template will sync with the code in the F# 3.0 sample pack


Tuesday, July 10, 2012

Self Note:Type Provider Assembly Resolve


thanks to my co-worker, Vlad, i can solve the type provider type assembly resolve problem. 

the code is below.

// tpc :TypeProviderConfig argument exposes enviroment-related information to the type provider
[< Microsoft.FSharp.Core.CompilerServices.TypeProvider >]
type TP(tpc : Microsoft.FSharp.Core.CompilerServices.TypeProviderConfig) =
    inherit TypeProviderForNamespaces()
   
    let handler = System.ResolveEventHandler(fun _ args ->
        let asmName = AssemblyName(args.Name)
        // assuming that we reference only dll files
        let expectedName = asmName.Name + ".dll"
        let expectedLocation =
            // we expect to find this assembly near the dll with type provider
            let d = IO.Path.GetDirectoryName(tpc.RuntimeAssembly)
            IO.Path.Combine(d, expectedName)
        if IO.File.Exists expectedLocation then Assembly.LoadFrom expectedLocation else null
        )
    do System.AppDomain.CurrentDomain.add_AssemblyResolve handler
   
    interface System.IDisposable with
        member this.Dispose() = System.AppDomain.CurrentDomain.remove_AssemblyResolve handler