After comparing the IL generated by F# compiler and that by C#/VB.NET compiler, I noticed that [<ExtensionAttribute>] was required to be applied to the module, just as follows:

1
2
3
4
5
6
7
8
9
10
11
#light

[<System.Runtime.CompilerServices.ExtensionAttribute>]
module Lib.Ext

#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5"
#r "System.Core.dll"
    
[<System.Runtime.CompilerServices.ExtensionAttribute>]
let PrintBook (b: Lib.Book) =
    printfn "%s by %s" b.Title b.Authors

Now PrintBook works fine in C# 3.0. Here's the question left to be answered:

  1. Will the underlying implementation of Type Extension be migrated to Extension Method? Or there will be two different ways for extending types?

Thanks in advance!

By on 7/22/2008 1:32 AM ()

Hi Allen,

Yes, we're planning to emit the ExtensionAttribute when it makes sense to do so.

Kind regards

don

By on 7/23/2008 4:21 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper