If I have a class with read-only properties that I only want to be created at constructor time e.g.:-
vb.net Code:
Imports System.Runtime.Serialization ''' <summary> ''' An event to indicate that an FX rate was priced between two currencies ''' </summary> <DataContract()> Public Class FXRatePricedEvent Inherits AggregateIdentity.CurrencyExchangeAggregateIdentity Implements IEvent(Of IAggregateIdentity) <DataMember(Name:="Rate")> ReadOnly m_rate As Decimal <DataMember(Name:="PriceDate")> ReadOnly m_pricedate As Date <DataMember(Name:="IsDerived")> ReadOnly m_derived As Boolean ''' <summary> ''' The conversion rate between source and target currencies ''' </summary> ReadOnly Property Rate As Decimal Get Return m_rate End Get End Property ''' <summary> ''' The date/time the FX rate was priced ''' </summary> ReadOnly Property PriceDate As Date Get Return m_pricedate End Get End Property ''' <summary> ''' Is this rate derived from triangulation or reversal of a priced rate ''' </summary> ''' <remarks> ''' For example a derived GBPJPY can exist s if a priced GBPUSD and USDJPY exist ''' </remarks> ReadOnly Property IsDerived As Boolean Get Return m_derived End Get End Property Public Sub New(ByVal currencyFrom As AggregateIdentity.CurrencyAggregateIdentity.ISO_3Digit_Currency, ByVal currencyTo As AggregateIdentity.CurrencyAggregateIdentity.ISO_3Digit_Currency, ByVal fxRate As Decimal, ByVal rateDate As Date, ByVal derived As Boolean) ' Set the FX rate aggregate identifier MyBase.New(currencyFrom, currencyTo) ' and set the other properties m_rate = fxRate m_pricedate = rateDate m_derived = derived End Sub 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?




Reply With Quote