0

I need to be able to change the value the variable "timeMins" at runtime in the JSON container class below. But, the only way that VB.Net allows me to do this is to declare "timeMins" as a Constant - However, constants cannot be changed at runtime as far as I know in VB.net.

Below is what I have so far...It compiles and runs, but does not do what I need it to do.

     Const timeMins As String = "15"


     Public Class JSON_Container_Real_Time
        <JsonProperty(PropertyName:="Meta Data")>
        Private Meta As MetaData
        <JsonProperty(PropertyName:="Time Series (" + timeMins + "min)")>
        Public Time_Series_Daily As Dictionary(Of String, StockInfo)
     End Class
PiE
  • 335
  • 1
  • 7
  • 24
  • Possible duplicate of [Newtonsoft JSON dynamic property name](https://stackoverflow.com/questions/37917164/newtonsoft-json-dynamic-property-name) – Visual Vincent Jul 20 '18 at 09:18

1 Answers1

1

In its current state what you're trying to do is not possible. At namespace level you're only allowed to declare types and constants, so you would need to move the variable declaration inside your class in order to be able to make it a non-constant. However, this means that you cannot use it in the JsonProperty attribute, because attributes require constant values only.

You would have to look for another solution to serialize/deserialize you class.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75