Example #1
0
        public virtual object Deserialize(string input, Type type)
        {
            lock (_lock)
            {
                for (var i = 0; i < encoders.Count; i++)
                {
                    try
                    {
                        ITypeEncoder encoder = encoders[i];
                        if (!encoder.IsSupport(type))
                        {
                            continue;
                        }

                        return(encoder.Decode(type, input));
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            throw new NotSupportedException(string.Format("This value \"{0}\" cannot be converted to the type \"{1}\"",
                                                          input, type.Name));
        }
Example #2
0
        public virtual string Serialize(object value)
        {
            lock (_lock)
            {
                for (var i = 0; i < encoders.Count; i++)
                {
                    try
                    {
                        ITypeEncoder encoder = encoders[i];
                        if (!encoder.IsSupport(value.GetType()))
                        {
                            continue;
                        }

                        return(encoder.Encode(value));
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            throw new NotSupportedException(string.Format("Unsupported type, this value \"{0}\" cannot be serialized",
                                                          value));
        }
Example #3
0
        public virtual string Serialize(object value)
        {
            lock (_lock)
            {
                for (int i = 0; i < _encoders.Count; i++)
                {
                    try
                    {
                        ITypeEncoder encoder = _encoders[i];
                        if (!encoder.IsSupport(value.GetType()))
                        {
                            continue;
                        }

                        return(encoder.Encode(value));
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }

            throw new NotSupportedException($"Unsupported type, this value \"{value}\" cannot be serialized");
        }
Example #4
0
        public virtual string Serialize(object value)
        {
            lock (_lock)
            {
                for (int i = 0; i < encoders.Count; i++)
                {
                    try
                    {
                        ITypeEncoder encoder = encoders[i];
                        if (!encoder.IsSupport(value.GetType()))
                        {
                            continue;
                        }

                        return(encoder.Encode(value));
                    }
                    catch (Exception) { }
                }
            }
            throw new NotSupportedException();
        }
Example #5
0
        public virtual object Deserialize(string input, Type type)
        {
            lock (_lock)
            {
                for (int i = 0; i < encoders.Count; i++)
                {
                    try
                    {
                        ITypeEncoder encoder = encoders[i];
                        if (!encoder.IsSupport(type))
                        {
                            continue;
                        }

                        return(encoder.Decode(type, input));
                    }
                    catch (Exception) { }
                }
            }
            throw new NotSupportedException();
        }