Exemplo n.º 1
0
        public object Get()
        {
            if (Content == null || TypeName == null)
            {
                return(null);
            }
            var typeName = Type.GetType(TypeName);

            if (typeName == typeof(JObject))
            {
                var content = SerializerUtilitys.Deserialize <string>(Content);
                return(JsonConvert.DeserializeObject <JObject>(content));
            }
            else
            {
                return(SerializerUtilitys.Deserialize(Content, typeName));
            }
        }
Exemplo n.º 2
0
        public MessagePackDynamicItem(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();
            var code      = Type.GetTypeCode(valueType);

            if (code != TypeCode.Object && valueType.BaseType != typeof(Enum))
            {
                TypeName = valueType.FullName;
            }
            else
            {
                TypeName = valueType.AssemblyQualifiedName;
            }

            Content = SerializerUtilitys.Serialize(value);
        }
Exemplo n.º 3
0
        public ProtoBufferTransportMessage(TransportMessage transportMessage)
        {
            Id          = transportMessage.Id;
            ContentType = transportMessage.ContentType;

            object contentObject;

            if (transportMessage.IsInvokeMessage())
            {
                contentObject = new ProtoBufferRemoteInvokeMessage(transportMessage.GetContent <RemoteInvokeMessage>());
            }
            else if (transportMessage.IsInvokeResultMessage())
            {
                contentObject = new ProtoBufferRemoteInvokeResultMessage(transportMessage.GetContent <RemoteInvokeResultMessage>());
            }
            else
            {
                throw new NotSupportedException($"无法支持的消息类型:{ContentType}!");
            }

            Content = SerializerUtilitys.Serialize(contentObject);
        }
Exemplo n.º 4
0
        public ProtoBufferDynamicItem(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var valueType = value.GetType();
            var code      = Type.GetTypeCode(valueType);

            //如果是简单类型则取短名称,否则取长名称。
            if (code != TypeCode.Object)
            {
                TypeName = valueType.FullName;
            }
            else
            {
                TypeName = valueType.AssemblyQualifiedName;
            }

            Content = SerializerUtilitys.Serialize(value);
        }
Exemplo n.º 5
0
        public object Get()
        {
            if (Content == null || TypeName == null)
            {
                return(null);
            }

            var typeName = Type.GetType(TypeName);

            if (typeName == UtilityType.JObjectType || typeName == UtilityType.JArrayType)
            {
                var content = SerializerUtilitys.Deserialize <string>(Content);
                return(JsonConvert.DeserializeObject(content, typeName));
            }
            else if (typeName == null)
            {
                var content = SerializerUtilitys.Deserialize <string>(Content);
                return(content);
            }
            else
            {
                return(SerializerUtilitys.Deserialize(Content, typeName));
            }
        }
Exemplo n.º 6
0
        public TransportMessage Decode(byte[] data)
        {
            var message = SerializerUtilitys.Deserialize <MessagePackTransportMessage>(data);

            return(message.GetTransportMessage());
        }
Exemplo n.º 7
0
 public void Deserialize(byte[] data)
 {
     Checkbit = 0x1F;
     Body     = SerializerUtilitys.DeSerialize <TMessage>(data);
 }