I’m starting to test a Application.Browser.LocalStorage.GetValue and Application.Browser.LocalStorage.SetValue
GetValue < CustomType > (…) fails, it seems not be deserialized. Invalid conversion from string to CustomType
Thanks in advance!
As Tiago mentions, only primitive types are supported. A JSON serialiser (I personally use Newtonsoft) can be used to take your object to a string, then you store the string in local storage. Retrieving is just the opposite, retrieve the string, then “de”serialise back to the original object. Works like a charm.
The browser LocalStorage (and SessionStorage for that matter) only store strings (DOMString as defined by the W3C Recommendation)
This means only strings are stored “as is”. Wisej takes care of type conversion for some types: primitives, value types, DateTime, Guid and types that can be converted from string using Convert.ChangeType.
The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single. Please refer to Type.IsPrimitive.
Value types are types that are represented as sequences of bits; value types are not classes or interfaces. Value types are referred to as “structs” in some programming languages. Enums are a special case of value types. Please refer to Type.IsValueType.
In a nutshell custom types aren’t supported. I suggest you serialize the intended type to get a storable string. To get the custom type back, use GetValue<string> and deserialize the string to the intended type. You can serialize and deserialize your type as JSON, but Wisej own JSON serializer/parser is optimized for speed (and it’s indeed very fast) but only supports the above types.
Hope that helps.
Please login first to submit.