我阅读了以下文章
http://studentguru.gr/b/kron/archive/2012/09/26/c-template-metaprogramming-and-f-type-providers.aspx
它显示了一种使用 F# 类型提供程序进行编译时斐波那契序列生成的方法。解决方案在文章中,但最终程序是
> cat .\fib.fs
type fib = Playground.StaticFibonacci<100000>
printfn "Fibonacci(100000) has %d digits" fib.Value.Length
> fsc .\fib.fs -o fib.exe -r:.\FibonacciTypeProvider.dll –nologo
> .\fib.exe
Fibonacci(100000) has 20899 digits
这看起来很强大。我想知道是否可以为 INPC ( INotifyPropertyChanged ) 创建一个类型提供程序,这样您就可以代替
open System.ComponentModel
type MyObject() =
let mutable propval = 0.0
let propertyChanged = Event<_, _>()
interface INotifyPropertyChanged with
[<clievent>]
member x.PropertyChanged = propertyChanged.Publish
member this.MyProperty
with get() = propval
and set(v) =
propval <- v
propertyChanged.Trigger(this, new PropertyChangedEventArgs("MyProperty"))
你也许可以写
open System.ComponentModel
type MyObject() =
let mutable propval = 0.0
let propertyChanged = Event<_, _>()
interface INotifyPropertyChanged with
[<clievent>]
member x.PropertyChanged = propertyChanged.Publish
member this.MyProperty : INPCTypeProvider<double>
因此,在我浪费半天时间深入研究这个问题之前,也许更知情的人会告诉我我在浪费时间,而且这种级别的元编程是不可能的。