namespace Samples.FSharp.HDF5TypeProvider open System.Reflection open Microsoft.FSharp.Core.CompilerServices open Samples.FSharp.ProvidedTypes open HelperFunctions open HDF5TypeWrappers open System.IO [] type public HDF5TypeProvider(tpcfg: TypeProviderConfig) as this= inherit TypeProviderForNamespaces() // Get the assembly and namespace used to house the provided types let thisAssembly = Assembly.GetExecutingAssembly() let rootNamespace = "Samples.TypeProviders" let nameOfProvidedType = "HDF5File" let baseType = typeof // The root type provided by this type provider. // Also see the static parameter function below. let tpForHDF5File = ProvidedTypeDefinition(thisAssembly, rootNamespace, nameOfProvidedType, Some baseType) // This type provider is always parametrized with the file name of the (static) file in question. let filenameParameterStatic = ProvidedStaticParameter("filename", typeof) // A file name for the file accessed at run-time must be provided as well. let filenameParameterDynamic = ProvidedParameter("filename", typeof) // The static parameter is given as "generic" type parameter to the provided type. let staticparam (nameOfType) (SingleElementArray (filenameObj: obj)) = // Resolve the filename relative to the resolution folder. // A relative path given at design-time is relative to the solution being built. let resolvedFilename = Path.Combine(tpcfg.ResolutionFolder, filenameObj :?> string) // Define the provided type. At run-time the type is HDFFile. let providedType = ProvidedTypeDefinition(thisAssembly, rootNamespace, nameOfType, Some(typeof)) // The constructor takes the file name of the actual HDF5 file to access, which may or may not be the same as the static file name. let ctor1 = ProvidedConstructor([filenameParameterDynamic], InvokeCode = fun (SingleElementList filename) -> <@@ HDFFile(%%filename : string) @@>) providedType.AddMember ctor1 // Add properties at design-time; do this by adding a property named "Root" that represents the root group of the HDF5 file. addRootProperty providedType resolvedFilename // The provided type is the result you get when supplying the static parameter (the HDF5 template file name) providedType // The static parameter function above is where we actually define the provided type, // without which tpForHDF5File is just a System.Object do tpForHDF5File.DefineStaticParameters([filenameParameterStatic], staticparam) // Add some comment for the type do tpForHDF5File.AddXmlDocDelayed (fun () -> "Provided type used as wrapper for HDF5 file.") // Finally add the provided type to the namespace do this.AddNamespace(rootNamespace, [tpForHDF5File]) [] do ()