2 people like it.

ZipProvider

Zip file type provider

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
module ZipProvider
open System.IO
open System.IO.Compression
open Samples.FSharp.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices

type ZipArchiveEntry with
  member arh.Text=
    use rdr=new StreamReader(arh.Open())
    rdr.ReadToEnd()

[<TypeProvider>]
type ZipPr() as this =
    inherit TypeProviderForNamespaces()
    let asm,ns = System.Reflection.Assembly.GetExecutingAssembly(),"ZipProvider"
    let IniTy = ProvidedTypeDefinition(asm, ns, "ZipProv", None)
    do IniTy.DefineStaticParameters(
         [ProvidedStaticParameter("path", typeof<string>)],
          fun tyName [|:? string as path|] ->
           let ty = ProvidedTypeDefinition(asm, ns, tyName, None)
           ProvidedConstructor([ProvidedParameter("path",typeof<string>)],
                               InvokeCode=(fun [path]-> <@@ ZipFile.OpenRead(%%path:string) @@>))
             |>ty.AddMember 
           ZipFile.OpenRead(path).Entries
             |>Seq.map (fun ent->let name=ent.FullName
                                 ProvidedProperty(name,typeof<ZipArchiveEntry>,
                                                  GetterCode=fun [arg] -> <@@ ((%%arg:obj):?>ZipArchive).GetEntry(name) @@>))
             |>Seq.toList|>ty.AddMembers
           ty)
       this.AddNamespace(ns, [IniTy])
[<TypeProviderAssembly>]
do()
module ZipProvider
namespace System
namespace System.IO
namespace System.IO.Compression
namespace Microsoft.FSharp
namespace Microsoft
namespace Microsoft.FSharp.Core
namespace Microsoft.FSharp.Core.CompilerServices
Multiple items
type StreamReader =
  inherit TextReader
  new : stream:Stream -> StreamReader + 9 overloads
  member BaseStream : Stream
  member Close : unit -> unit
  member CurrentEncoding : Encoding
  member DiscardBufferedData : unit -> unit
  member EndOfStream : bool
  member Peek : unit -> int
  member Read : unit -> int + 1 overload
  member ReadLine : unit -> string
  member ReadToEnd : unit -> string
  ...

Full name: System.IO.StreamReader

--------------------
StreamReader(stream: Stream) : unit
StreamReader(path: string) : unit
StreamReader(stream: Stream, detectEncodingFromByteOrderMarks: bool) : unit
StreamReader(stream: Stream, encoding: System.Text.Encoding) : unit
StreamReader(path: string, detectEncodingFromByteOrderMarks: bool) : unit
StreamReader(path: string, encoding: System.Text.Encoding) : unit
StreamReader(stream: Stream, encoding: System.Text.Encoding, detectEncodingFromByteOrderMarks: bool) : unit
StreamReader(path: string, encoding: System.Text.Encoding, detectEncodingFromByteOrderMarks: bool) : unit
StreamReader(stream: Stream, encoding: System.Text.Encoding, detectEncodingFromByteOrderMarks: bool, bufferSize: int) : unit
StreamReader(path: string, encoding: System.Text.Encoding, detectEncodingFromByteOrderMarks: bool, bufferSize: int) : unit
Multiple items
type TypeProviderAttribute =
  inherit Attribute
  new : unit -> TypeProviderAttribute

Full name: Microsoft.FSharp.Core.CompilerServices.TypeProviderAttribute

--------------------
new : unit -> TypeProviderAttribute
Multiple items
type ZipPr =
  inherit obj
  new : unit -> ZipPr

Full name: ZipProvider.ZipPr

--------------------
new : unit -> ZipPr
val this : ZipPr
namespace System.Reflection
type Assembly =
  member CodeBase : string
  member CreateInstance : typeName:string -> obj + 2 overloads
  member EntryPoint : MethodInfo
  member Equals : o:obj -> bool
  member EscapedCodeBase : string
  member Evidence : Evidence
  member FullName : string
  member GetCustomAttributes : inherit:bool -> obj[] + 1 overload
  member GetCustomAttributesData : unit -> IList<CustomAttributeData>
  member GetExportedTypes : unit -> Type[]
  ...

Full name: System.Reflection.Assembly
System.Reflection.Assembly.GetExecutingAssembly() : System.Reflection.Assembly
union case Option.None: Option<'T>
val typeof<'T> : System.Type

Full name: Microsoft.FSharp.Core.Operators.typeof
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
module Seq

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
type obj = System.Object

Full name: Microsoft.FSharp.Core.obj
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
Multiple items
type TypeProviderAssemblyAttribute =
  inherit Attribute
  new : unit -> TypeProviderAssemblyAttribute
  new : assemblyName:string -> TypeProviderAssemblyAttribute
  member AssemblyName : string

Full name: Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute

--------------------
new : unit -> TypeProviderAssemblyAttribute
new : assemblyName:string -> TypeProviderAssemblyAttribute

More information

Link:http://fssnip.net/n6
Posted:9 years ago
Author:Zhukoff Dima
Tags: typeprovider , data , zip