示例#1
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (_typeNameShortener.TryShorten((Type)value, out var shortName))
     {
         writer.WriteValue(shortName);
     }
     else
     {
         writer.WriteValue(value.ToString());
     }
 }
示例#2
0
        public IValueContainer Decompose(object value)
        {
            var ex = (Exception)value;

            return(new ExceptionContainer
            {
                Type = _typeNameShortener.TryShorten(ex.GetType(), out string shortName) ? shortName : ex.GetType().AssemblyQualifiedName,
                Message = ex.Message,
                InnerException = (ex is AggregateException) ? null : ex.InnerException,
                InnerExceptions = (ex is AggregateException aggregateException) ? aggregateException.InnerExceptions.ToArray() : null,
                StackTrace = ex.StackTrace
            });
示例#3
0
        private TypeSerializationInfo GetTypeSerializationInfo(Type type)
        {
#warning Ignore types from dynamic assemblies

            if (_typeNameShortener.TryShorten(type, out var typeShortName))
            {
                return(new TypeSerializationInfo
                {
                    Name = typeShortName
                });
            }
            else if (type.IsGenericType() && _typeNameShortener.TryShorten(
                         type.GetGenericTypeDefinition(), out typeShortName))
            {
                return(new TypeSerializationInfo
                {
                    Name = typeShortName,
                    GenericArgs = type.GetGenericArguments().Select(t => GetTypeSerializationInfo(t)).ToArray()
                });
            }
            else if (_assemblyNameShortener.TryShorten(type.GetAssembly(), out string assemblyShortName))
            {
                return(new TypeSerializationInfo
                {
                    Name = type.GetFullName(),
                    Assembly = new AssemblySerializationInfo
                    {
                        Name = assemblyShortName
                    },
                    GenericArgs = type.IsGenericType()
                        ? type.GetGenericArguments().Select(t => GetTypeSerializationInfo(t)).ToArray()
                        : null
                });
            }
            else
            {
                return(type.ToTypeSerializationInfo());
            }
        }
示例#4
0
        public IValueContainer Decompose(object value)
        {
#warning Add support for multi-projection. Need to know the variable/result type - a bigger serializer problem :( Also possibly need to know if it's a cross-domain derialization to keep the entity instance.
            var projectionInterface = value.GetType().GetInterfaces()
                                      .First(i => KnownEntityProjectionInterfaces != null
                    ? KnownEntityProjectionInterfaces.Contains(i)
                    : EntityProjection.IsProjectionInterface(i));

            var container = new EntityProjectionContainer
            {
                Type       = _typeNameShortener.TryShorten(projectionInterface, out string shortName) ? shortName : projectionInterface.ToString(),
                Properties = new Dictionary <string, object>()
            };

#warning Add properties of base interface(s)
            foreach (var property in projectionInterface.GetProperties())
            {
                container.Properties.Add(property.Name, property.GetValue(value));
            }

            return(container);
        }