明确null类型

This commit is contained in:
ww-rm
2025-04-28 20:21:31 +08:00
parent ca7e94a306
commit 9f618804df

View File

@@ -168,7 +168,7 @@ namespace SpineViewer.Spine
// 无符号右移, 符号按原样设置在最高位, 其他位与符号异或 // 无符号右移, 符号按原样设置在最高位, 其他位与符号异或
return optimizePositive ? val : (val >>> 1) ^ -(val & 1); return optimizePositive ? val : (val >>> 1) ^ -(val & 1);
} }
public string ReadString() public string? ReadString()
{ {
int byteCount = ReadVarInt(); int byteCount = ReadVarInt();
switch (byteCount) switch (byteCount)
@@ -181,7 +181,7 @@ namespace SpineViewer.Spine
ReadFully(buffer, 0, byteCount); ReadFully(buffer, 0, byteCount);
return System.Text.Encoding.UTF8.GetString(buffer, 0, byteCount); return System.Text.Encoding.UTF8.GetString(buffer, 0, byteCount);
} }
public string ReadStringRef() public string? ReadStringRef()
{ {
int index = ReadVarInt(); int index = ReadVarInt();
return index == 0 ? null : StringTable[index - 1]; return index == 0 ? null : StringTable[index - 1];
@@ -276,7 +276,7 @@ namespace SpineViewer.Spine
} }
output.WriteByte(b); output.WriteByte(b);
} }
public void WriteString(string val) public void WriteString(string? val)
{ {
if (val == null) if (val == null)
{ {
@@ -294,7 +294,7 @@ namespace SpineViewer.Spine
System.Text.Encoding.UTF8.GetBytes(val, 0, val.Length, buffer, 0); System.Text.Encoding.UTF8.GetBytes(val, 0, val.Length, buffer, 0);
WriteFully(buffer, 0, byteCount); WriteFully(buffer, 0, byteCount);
} }
public void WriteStringRef(string val) public void WriteStringRef(string? val)
{ {
if (val is null) if (val is null)
{ {