/// <summary>
        /// Gets arg writer for platform-compatible service calls.
        /// </summary>
        private static Action <BinaryWriter, object> GetPlatformArgWriter(ParameterInfo param, object arg)
        {
            var type = param.ParameterType;

            // Unwrap nullable
            type = Nullable.GetUnderlyingType(type) ?? type;

            if (arg == null || type.IsPrimitive)
            {
                return(null);
            }

            var handler = BinarySystemHandlers.GetWriteHandler(type);

            if (handler != null)
            {
                return(null);
            }

            if (type.IsArray)
            {
                return((writer, o) => writer.WriteArrayInternal((Array)o));
            }

            if (arg is ICollection)
            {
                return((writer, o) => writer.WriteCollection((ICollection)o));
            }

            return(null);
        }
        /// <summary>
        /// Gets arg writer for platform-compatible service calls.
        /// </summary>
        private static Action <BinaryWriter, object> GetPlatformArgWriter(Type paramType, object arg)
        {
            if (arg == null)
            {
                return(null);
            }

            var type = paramType ?? arg.GetType();

            // Unwrap nullable
            type = Nullable.GetUnderlyingType(type) ?? type;

            if (type.IsPrimitive)
            {
                return(null);
            }

            if (type.IsArray)
            {
                Type elemType = type.GetElementType();

                if (elemType == typeof(Guid?))
                {
                    return((writer, o) => writer.WriteGuidArray((Guid?[])o));
                }
                else if (elemType == typeof(DateTime?))
                {
                    return((writer, o) => writer.WriteTimestampArray((DateTime?[])o));
                }
            }

            var handler = BinarySystemHandlers.GetWriteHandler(type);

            if (handler != null)
            {
                return(null);
            }

            if (type.IsArray)
            {
                return((writer, o) => writer.WriteArrayInternal((Array)o));
            }

            if (arg is IDictionary)
            {
                return((writer, o) => writer.WriteDictionary((IDictionary)o));
            }

            if (arg is ICollection)
            {
                return((writer, o) => writer.WriteCollection((ICollection)o));
            }

            if (arg is DateTime)
            {
                return((writer, o) => writer.WriteTimestamp((DateTime)o));
            }

            return(null);
        }