If I have a class with read-only properties that I only want to be created at constructor time e.g.:-


vb.net Code:
  1. Imports System.Runtime.Serialization
  2.  
  3. ''' <summary>
  4. ''' An event to indicate that an FX rate was priced between two currencies
  5. ''' </summary>
  6. <DataContract()>
  7. Public Class FXRatePricedEvent
  8.     Inherits AggregateIdentity.CurrencyExchangeAggregateIdentity
  9.     Implements IEvent(Of IAggregateIdentity)
  10.  
  11.     <DataMember(Name:="Rate")>
  12.     ReadOnly m_rate As Decimal
  13.     <DataMember(Name:="PriceDate")>
  14.     ReadOnly m_pricedate As Date
  15.     <DataMember(Name:="IsDerived")>
  16.     ReadOnly m_derived As Boolean
  17.  
  18.  
  19.     ''' <summary>
  20.     ''' The conversion rate between source and target currencies
  21.     ''' </summary>
  22.     ReadOnly Property Rate As Decimal
  23.         Get
  24.             Return m_rate
  25.         End Get
  26.     End Property
  27.  
  28.     ''' <summary>
  29.     ''' The date/time the FX rate was priced
  30.     ''' </summary>
  31.     ReadOnly Property PriceDate As Date
  32.         Get
  33.             Return m_pricedate
  34.         End Get
  35.     End Property
  36.  
  37.     ''' <summary>
  38.     ''' Is this rate derived from triangulation or reversal of a priced rate
  39.     ''' </summary>
  40.     ''' <remarks>
  41.     ''' For example a derived GBPJPY can exist s if a priced GBPUSD and USDJPY exist
  42.     ''' </remarks>
  43.     ReadOnly Property IsDerived As Boolean
  44.         Get
  45.             Return m_derived
  46.         End Get
  47.     End Property
  48.  
  49.     Public Sub New(ByVal currencyFrom As AggregateIdentity.CurrencyAggregateIdentity.ISO_3Digit_Currency,
  50.                    ByVal currencyTo As AggregateIdentity.CurrencyAggregateIdentity.ISO_3Digit_Currency,
  51.                    ByVal fxRate As Decimal,
  52.                    ByVal rateDate As Date,
  53.                    ByVal derived As Boolean)
  54.         ' Set the FX rate aggregate identifier
  55.         MyBase.New(currencyFrom, currencyTo)
  56.         ' and set the other properties
  57.         m_rate = fxRate
  58.         m_pricedate = rateDate
  59.         m_derived = derived
  60.     End Sub
  61.  
  62. End Class

Then System.Runtime.Serialization can serialise this to/from XML with no problem. However I want to do something similar but to a key-value pair dictionary....my attempts so to do hit a brick wall unless the class has a constructor with no parameters.

Any ideas how I (or they) get around this?