Eric Eric - 3 months ago 17
ASP.NET (C#) Question

F# using HttpPostedFileBase (abstract class as member type)

I've been converting my MVC Models/Forms from C# into an F# library, but can't seem to figure this one out. I use HttpPostedFileBase in the original C# model, but I'm confused how to write an F# type that would work in a similar fashion.

// C#
public class UploadForm()
{
public int ItemID { get; set; }
public string Email { get; set; }
public HttpPostedFileBase UploadFile { get; set; }
// UploadFile is the name of the HTML file input on the Razor view
}


// F#
type UploadForm() =
member val ItemID = 0 with get, set
member val Email = "" with get, set
member val UploadFile = ???


I read the F# documentation on abstract properties, but I'm not overriding any properties here... just trying to say that a given member (UploadFile) should be of a certain type (HttpPostedFileBase). Is this possible or do I need to write backing code?

Answer

you can give a type in the usual way like this:

type UploadForm() = 
    // ... other members
    member val UploadFile : HttpPostedFileBase = null with get, set