Last active
December 19, 2015 22:59
-
-
Save vasily-kirichenko/6031546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Samples.FSharp.TestTypeProvider | |
| open System.Reflection | |
| open Microsoft.FSharp.Core.CompilerServices | |
| open Samples.FSharp.ProvidedTypes | |
| open System.IO | |
| open Microsoft.FSharp.Quotations | |
| [<TypeProvider>] | |
| type public TypeProvider1() as this = | |
| inherit TypeProviderForNamespaces() | |
| let thisAssembly = Assembly.GetExecutingAssembly() | |
| let rootNamespace = "Samples.ShareInfo.TPTest" | |
| let baseTy = typeof<obj> | |
| let assembly = ProvidedAssembly @"d:\_tt_.dll" | |
| let t = ProvidedTypeDefinition(thisAssembly, rootNamespace, "TPTestType", Some baseTy, | |
| IsErased=false, SuppressRelocation=false) | |
| do | |
| let field = ProvidedField ("data", typeof<string>) | |
| t.AddMember( | |
| ProvidedConstructor( | |
| [ ProvidedParameter ("input", typeof<string>) ], | |
| InvokeCode = fun [me; arg] -> | |
| let set = Expr.FieldSet (me, field, <@@ (%%arg: string) @@>) | |
| <@@ (%%set: unit) @@>)) | |
| t.AddMember( | |
| ProvidedProperty( | |
| "Data", | |
| typeof<string>, | |
| GetterCode = fun [me] -> Expr.FieldGet (me, field))) | |
| t.AddMember field | |
| assembly.AddTypes [t] | |
| this.AddNamespace (rootNamespace, [t]) | |
| [<TypeProviderAssembly>] | |
| do () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment