I think you want

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
type MyClass() = class
    member x.Convert1<'T> (v:obj) : 'T=
        let typ = typeof<'T>
        System.Convert.ChangeType(v, typ) :?> 'T
    
    member x.Convert2<'T> (v:obj) : 'T=      
        let typ = typeof<'T>
        //I would like to control the conversion for some of the types
        if typ = typeof<System.Int32> then
            (box 2) :?> 'T
        elif typ = typeof<System.Int64> then
            (box 2L) :?> 'T
        else x.Convert1<'T> v
end
By on 5/18/2009 3:06 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