Beispiel #1
0
        public object GetValue()
        {
            if (Data == null)
            {
                return(null);
            }
            if (SerializedObjects.TryGetValue(Data, out var value))
            {
                return(value);
            }
            var type = string.IsNullOrWhiteSpace(DataType) ? typeof(object) : Core.GetType(DataType, true);

            if (string.IsNullOrWhiteSpace(SerializerMimeType))
            {
                return(type == typeof(byte[]) ? Data : null);
            }
            var idx        = SerializerMimeType.IndexOf(':');
            var serMime    = idx < 0 ? SerializerMimeType : SerializerMimeType.Substring(0, idx);
            var serComp    = idx < 0 ? null : SerializerMimeType.Substring(idx + 1);
            var serializer = SerializerManager.GetByMimeType(serMime);

            if (serializer == null)
            {
                throw new FormatException($"The serializer with MimeType = {serMime} wasn't found.");
            }
            if (!string.IsNullOrWhiteSpace(serComp))
            {
                serializer.Compressor = CompressorManager.GetByEncodingType(serComp);
            }
            value = serializer.Deserialize(Data, type);
            SerializedObjects.TryAdd(Data, value);
            return(value);
        }
Beispiel #2
0
        private static ISerializer CreateSerializer(string serMimeType)
        {
            var idx     = serMimeType.IndexOf(':');
            var serMime = idx < 0 ? serMimeType : serMimeType.Substring(0, idx);
            var serComp = idx < 0 ? null : serMimeType.Substring(idx + 1);
            var ser     = SerializerManager.GetByMimeType(serMime);

            if (ser is null)
            {
                ThrowSerializerNotFound(serMime);
            }
            if (!string.IsNullOrWhiteSpace(serComp))
            {
                ser.Compressor = CompressorManager.GetByEncodingType(serComp);
            }
            return(ser);
        }
Beispiel #3
0
 void ICoreStart.AfterFactoryInit(Factories factories)
 => SerializerManager.Register(this);
Beispiel #4
0
 public void CoreInit(Factories factories)
 => SerializerManager.Register(this);