-
-
Notifications
You must be signed in to change notification settings - Fork 216
Open
Description
Consider adding generics to the WriteMemory method to increase the clarity of the code, similar to the following code:
public bool WriteMemory<T>(UIntPtr address, T writeValue, bool removeProtection = false, Encoding encoding = null)
{
byte[] memory;
switch (writeValue)
{
case float floatValue:
memory = BitConverter.GetBytes(floatValue);
break;
case int intValue:
memory = BitConverter.GetBytes(intValue);
break;
case uint uintValue:
memory = BitConverter.GetBytes(uintValue);
break;
case byte byteValue:
memory = new byte[] { byteValue };
break;
case short shortValue: // 2byte
memory = BitConverter.GetBytes(shortValue);
break;
case double doubleValue:
memory = BitConverter.GetBytes(doubleValue);
break;
case long longValue:
memory = BitConverter.GetBytes(longValue);
break;
case UIntPtr UIntPtrValue:
if (MemProc.Is64Bit)
memory = BitConverter.GetBytes((ulong)UIntPtrValue);
else
memory = BitConverter.GetBytes((uint)UIntPtrValue);
break;
case string stringValue:
return WriteString(address, stringValue, encoding, removeProtection);
case byte[] bytesValue:
return WriteBytes(address, bytesValue, removeProtection);
default:
throw new ArgumentException($"Type \"{typeof(T).Name}\" is not support.");
}
This is a partial example, where some methods do not actually exist.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels