private static Expression Read(Type type, Expression reader, Expression target)
 {
     if (MessageShared.IsTypeArray(type))
     {
         var elementType = MessageShared.GetArrayElementType(type);
         return(MessageShared.PrimitiveArrayTypes.Contains(elementType) ? ReadPrimitiveArray(type, reader, target) : ReadArray(type, elementType, reader, target));
     }
     else
     {
         return(ReadNonArray(type, reader, target));
     }
 }
        private static Expression Write(Type type, Expression writer, Expression source)
        {
            if (MessageShared.IsTypeArray(type))
            {
                var elementType = MessageShared.GetArrayElementType(type);

                var nullCheck = Expression.Equal(source, Expression.Constant(null, type));
                return(Expression.IfThenElse(nullCheck,
                                             Write(typeof(int), writer, Expression.Constant(0)),
                                             MessageShared.PrimitiveArrayTypes.Contains(elementType) ? WritePrimitiveArray(type, writer, source) : WriteArray(type, elementType, writer, source)));
            }
            else
            {
                return(WriteNonArray(type, writer, source));
            }
        }