Port to .NET Framework 4.8 with C# 9.0 compatibility

- Change target framework from net6.0 to net48 with LangVersion 9.0
- Remove nullable reference types for .NET Framework compatibility
- Replace Convert.FromHexString/ToHexString with custom implementations
- Fix switch pattern matching to use traditional case statements
- Replace range operators with LINQ Take/Skip and Array.Copy
- Replace Math.Log2 with Math.Log(p)/Math.Log(2) formula
- Fix Contains method calls to use ToLower() instead of StringComparison

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-07 20:02:22 +09:00
parent 4f2f6a99d7
commit e09c63080e
3 changed files with 58 additions and 24 deletions

View File

@@ -8,6 +8,18 @@ namespace V2GProtocol
{
public class V2GDecoder
{
static byte[] FromHexString(string hexString)
{
if (hexString.Length % 2 != 0)
throw new ArgumentException("Invalid hex string length");
byte[] bytes = new byte[hexString.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return bytes;
}
private const byte V2G_TP_VERSION = 0x01;
private const byte V2G_TP_INVERSE_VERSION = 0xFE;
@@ -420,7 +432,7 @@ namespace V2GProtocol
if (byteCounts[i] > 0)
{
double p = (double)byteCounts[i] / totalBytes;
entropy -= p * Math.Log2(p);
entropy -= p * (Math.Log(p) / Math.Log(2));
}
}
@@ -447,7 +459,7 @@ namespace V2GProtocol
foreach (var keyword in v2gKeywords)
{
if (text.Contains(keyword, StringComparison.OrdinalIgnoreCase))
if (text.ToLower().Contains(keyword.ToLower()))
xmlIndicators += 2;
}
@@ -488,7 +500,7 @@ namespace V2GProtocol
foreach (var keyword in keywords)
{
if (dataAsString.Contains(keyword, StringComparison.OrdinalIgnoreCase))
if (dataAsString.ToLower().Contains(keyword.ToLower()))
{
found.Add(keyword);
}
@@ -1057,7 +1069,7 @@ namespace V2GProtocol
var sessionId = ExtractValueFromXML(xmlContent, "SessionID");
if (!string.IsNullOrEmpty(sessionId) && sessionId.Length == 16) // 8 bytes as hex
{
var sessionBytes = Convert.FromHexString(sessionId);
var sessionBytes = FromHexString(sessionId);
foreach (byte b in sessionBytes)
{
if (b >= 0x30 && b <= 0x5A) // ASCII range