我想知道这个错误来自哪里。这是代码,在使用 fsahrpx DSL 的 TP 下面
更新:我找到了一个“解决方案”,即在外面进行演员表,每次演员表构造一个吸气剂。如果有人知道为什么会发生这种情况,或者有更好的解决方案,我会很高兴知道。(ProvidedTypes-0.2.fs 中的有限引用模式?)
编辑:我绝望的失败尝试并不那么有趣。例如,两个有趣的是 Test93 或 Test92。他们为什么会失败?
更新 添加了最诉讼案件 90,91,92,93
module Module =
open System.Reflection
open Samples.FSharp.ProvidedTypes
open FSharpx.TypeProviders.DSL
open Microsoft.FSharp.Core.CompilerServices
type ReflectiveBuilder = static member Cast<'a> (args:obj) = args :?> 'a
static member BuildTypedCast lType (args: obj) =
typeof<ReflectiveBuilder>
.GetMethod("Cast")
.MakeGenericMethod([|lType|])
.Invoke(null, [|args|])
let bbgReference ns =
erasedType<obj> (Assembly.GetExecutingAssembly()) ns "Reference"
|> staticParameter "file"
(fun typeName (parameterValues:string) ->
let otwo = 2.0 :> obj
let dtwo = 2.0
let dotwo = otwo :?> float
let dcast = ReflectiveBuilder.BuildTypedCast typeof<float>
let getter = match otwo with
| :? double as d -> (fun args -> <@@ d @@>)
| :? string as d -> (fun args -> <@@ d @@>)
erasedType<string> (Assembly.GetExecutingAssembly()) ns typeName
|+!> ( provideProperty
"test90" //KO
(typeof<obj>)
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test91" //KO
(otwo.GetType())
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test92" //KO
(otwo.GetType())
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test93" //NO
typeof<float>
(fun args -> <@@ otwo :?> float @@>)
)
|+!> ( provideProperty
"test" //OK
typeof<float>
(fun args -> <@@ dtwo @@>)
)
|+!> ( provideProperty
"test2" //NO
typeof<float>
(fun args -> <@@ dtwo :> obj @@>)
)
|+!> ( provideProperty
"test3" //NO
typeof<float>
(fun args -> <@@ otwo @@>)
)
|+!> ( provideProperty
"test4" //NO
typeof<float>
(fun args -> <@@ otwo :?> float @@>)
)
|+!> ( provideProperty
"test5" //OK
typeof<float>
(fun args -> <@@ dotwo @@>)
)
|+!> ( provideProperty
"test6" //OK
typeof<float>
(fun args -> <@@ dotwo :> obj @@>)
)
|+!> ( provideProperty
"test7" //NO
typeof<float>
(fun args -> <@@ dcast otwo @@>)
)
|+!> ( provideProperty
"test8" //OK
typeof<float>
getter
)
|+!> (provideConstructor
[]
(fun _ -> <@@ "I will be the internal representation" @@>)))
[<TypeProvider>]
type public CustomTypeProvider(cfg:TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()
do this.AddNamespace("TEST", [bbgReference "TEST"])
[<TypeProviderAssembly>]
do()
测试
module Program =
open System
type t = TEST.Reference<"">
let price = t().Test90
let price = t().Test91
let price = t().Test92
let price = t().Test93
let price = t().Test //OK
let price = t().Test2 //OK
let price = t().Test3 //NO OK
let price = t().Test4 //NO OK
let price = t().Test5 //OK
let price = t().Test6 //OK
let price = t().Test7 //NO OK
let price = t().Test8 //OK