Skip to content

Commit

Permalink
基础API返回值尽可能不要返回null
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 5, 2016
1 parent c39f4a4 commit 90376b8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions NewLife.Core/IO/IOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,8 @@ public static Byte[] Reverse(this Byte[] buf)
/// <returns></returns>
public static String ToHex(this Byte[] data, Int32 offset = 0, Int32 count = -1)
{
if (data == null || data.Length < 1) return null;
if (data == null || data.Length < 1) return "";

if (count < 0)
count = data.Length - offset;
else if (offset + count > data.Length)
Expand Down Expand Up @@ -1094,7 +1095,8 @@ public static String ToHex(this Byte[] data, Int32 offset = 0, Int32 count = -1)
/// <returns></returns>
public static String ToHex(this Byte[] data, String separate, Int32 groupSize = 0, Int32 maxLength = -1)
{
if (data == null || data.Length < 1) return null;
if (data == null || data.Length < 1) return "";

if (groupSize < 0) groupSize = 0;

var count = data.Length;
Expand Down Expand Up @@ -1153,7 +1155,7 @@ private static char GetHexValue(int i)
/// <returns></returns>
public static Byte[] ToHex(this String data, Int32 startIndex = 0, Int32 length = -1)
{
if (String.IsNullOrEmpty(data)) return null;
if (String.IsNullOrEmpty(data)) return new Byte[0];

// 过滤特殊字符
data = data.Trim()
Expand Down Expand Up @@ -1185,7 +1187,8 @@ public static Byte[] ToHex(this String data, Int32 startIndex = 0, Int32 length
/// <returns></returns>
public static String ToBase64(this Byte[] data, Int32 offset = 0, Int32 count = -1, Boolean lineBreak = false)
{
if (data == null || data.Length < 1) return null;
if (data == null || data.Length < 1) return "";

if (count <= 0)
count = data.Length - offset;
else if (offset + count > data.Length)
Expand All @@ -1199,7 +1202,7 @@ public static String ToBase64(this Byte[] data, Int32 offset = 0, Int32 count =
/// <returns></returns>
public static Byte[] ToBase64(this String data)
{
if (String.IsNullOrEmpty(data)) return null;
if (String.IsNullOrEmpty(data)) return new Byte[0];

return Convert.FromBase64String(data);
}
Expand Down

0 comments on commit 90376b8

Please sign in to comment.