Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,11 @@ If using Paket, you can also add code files by direct GitHub references.

## The ProvidedTypes API - Cross-Targeting Type Providers

Type providers may be used in projects that generate portable code or target other .NET Frameworks than
that being used by the F# compiler. To convert an erasing
type provider to a cross-targeting erasing type provider, add the following source files to your project:

* AssemblyReader.fs
* AssemblyReaderReflection.fs
* ProvidedTypesContext.fs

Then add
Type providers may be used in projects that generate .NET Standard code or target other .NET Frameworks than
that being used to execute the F# compiler. Use

```fsharp
let ctxt = ProvidedTypesContext.Create(config)
let ctxt = ProvidedTypesContext.Create(config, isForGenerated=false)
```

to your code and always create provided entities using this ``ctxt`` object:
Expand All @@ -75,11 +68,11 @@ type BasicProvider (config : TypeProviderConfig) as this =

let ns = "StaticProperty.Provided"
let asm = Assembly.GetExecutingAssembly()
let ctxt = ProvidedTypesContext.Create(config)
let ctxt = ProvidedTypesContext.Create(config, isForGenerated=false)

let createTypes () =
let myType = ctxt.ProvidedTypeDefinition(asm, ns, "MyType", Some typeof<obj>)
let myProp = ctxt.ProvidedProperty("MyProperty", typeof<string>, IsStatic = true, getterCode = (fun args -> <@@ "Hello world" @@>))
let myProp = ctxt.ProvidedProperty("MyProperty", typeof<string>, IsStatic = true, GetterCode = (fun args -> <@@ "Hello world" @@>))
myType.AddMember(myProp)
[myType]

Expand Down
18 changes: 18 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#### 3.0.0 - October 9 2017
* All type providers now use a ProvidedTypesContext, e.g.
let ctxt = ProvidedTypesContext.Create(config, isForGenerated=false)
...
let myType = ctxt.ProvidedTypeDefinition(asm, ns, "MyType", Some typeof<obj>)
...
There are no more direct constructors for ProvidedTypeDefinition etc.

* ProvidedTypesContext.Create now takes a flag isForGenerated. It should be set to true for generative type providers

* IsStaticMethod becomes IsStatic and some other similar naming changes

* Direct setters such as prop.GetterCode <- ... are removed in favour of optional parameters. You must specify GetterCode as a parameter

* Enables use as part of .NET Core execution of the F# compiler by extending TypeDelegator instead of Type. This needs to be more fully tested but repo itself now compiles as both .NET Standard 2.0 and .NET Framework, and passes tests as both .NET CoreApp 2.0 and .NET Framework 4.6.1

* Puts everything into one file ProvidedTypes.fs and ProvidedTypes.fsi. This file is large but this approach makes it very easy for people writing existing type providers to update (after accounting for changes in the ProvidedTypes API)

#### 2.1.0 - August 25 2017
* Mono 5 support
* Parameter names unification
Expand Down
3 changes: 0 additions & 3 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ let srcDir = "src"
let sources =
[srcDir @@ "ProvidedTypes.fsi"
srcDir @@ "ProvidedTypes.fs"
srcDir @@ "AssemblyReader.fs"
srcDir @@ "AssemblyReaderReflection.fs"
srcDir @@ "ProvidedTypesContext.fs"
srcDir @@ "ProvidedTypesTesting.fs" ]

Target "Clean" (fun _ ->
Expand Down
10 changes: 5 additions & 5 deletions examples/ErasedWithConstructor.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ open Microsoft.FSharp.Core.CompilerServices
open System.Reflection

[<TypeProvider>]
type BasicProvider (config : TypeProviderConfig) as this =
type BasicErasingProvider (config : TypeProviderConfig) as this =
inherit TypeProviderForNamespaces ()

let ns = "ErasedWithConstructor.Provided"
let asm = Assembly.GetExecutingAssembly()
let ctxt = ProvidedTypesContext.Create(config)
let ctxt = ProvidedTypesContext.Create(config, false)

let createTypes () =
let myType = ctxt.ProvidedTypeDefinition(asm, ns, "MyType", Some typeof<obj>)

let ctor = ctxt.ProvidedConstructor([], invokeCode = fun args -> <@@ "My internal state" :> obj @@>)
let ctor = ctxt.ProvidedConstructor([], InvokeCode = fun args -> <@@ "My internal state" :> obj @@>)
myType.AddMember(ctor)

let ctor2 = ctxt.ProvidedConstructor([ctxt.ProvidedParameter("InnerState", typeof<string>)], invokeCode = fun args -> <@@ (%%(args.[0]):string) :> obj @@>)
let ctor2 = ctxt.ProvidedConstructor([ctxt.ProvidedParameter("InnerState", typeof<string>)], InvokeCode = fun args -> <@@ (%%(args.[0]):string) :> obj @@>)
myType.AddMember(ctor2)

let innerState = ctxt.ProvidedProperty("InnerState", typeof<string>, getterCode = fun args -> <@@ (%%(args.[0]) :> obj) :?> string @@>)
let innerState = ctxt.ProvidedProperty("InnerState", typeof<string>, GetterCode = fun args -> <@@ (%%(args.[0]) :> obj) :?> string @@>)
myType.AddMember(innerState)

[myType]
Expand Down
4 changes: 2 additions & 2 deletions examples/StaticProperty.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ type BasicProvider (config : TypeProviderConfig) as this =

let ns = "StaticProperty.Provided"
let asm = Assembly.GetExecutingAssembly()
let ctxt = ProvidedTypesContext.Create(config)
let ctxt = ProvidedTypesContext.Create(config, false)

let createTypes () =
let myType = ctxt.ProvidedTypeDefinition(asm, ns, "MyType", Some typeof<obj>)
let myProp = ctxt.ProvidedProperty("MyProperty", typeof<string>, IsStatic = true, getterCode = (fun args -> <@@ "Hello world" @@>))
let myProp = ctxt.ProvidedProperty("MyProperty", typeof<string>, IsStatic = true, GetterCode = (fun args -> <@@ "Hello world" @@>))
myType.AddMember(myProp)
[myType]

Expand Down
Loading