If you want two different constructors in a derived class to call into two different constructors in a base class, then you must use the 'explicit' class syntax, where there are no parens after the type/inherit declaration, and instance variables use 'val'.


Here's an example:


type SerializableDictionary<'TKey, 'TValue> = 
    inherit Dictionary<'TKey, 'TValue>
    val anotherInstanceVar : int
    new(info: SerializationInfo, context: StreamingContext) = {inherit Dictionary<'TKey, 'TValue>(info,context); anotherInstanceVar = 4}
    new() = {inherit Dictionary<'TKey, 'TValue>(); anotherInstanceVar = 0} 

This is one of the very few cases where you need to use this 'explicit' syntax rather than the preferred syntax involving a primary constructor.
By on 7/2/2009 12:47 PM ()

Thanks Brian - that works nicely.


By on 7/3/2009 8:46 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us
Built with WebSharper