Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,26 @@ private static object GetFieldDefaultValue(TypeDefinition cType, FieldDefinition
{
defaultValue = Convert.ToBoolean(loadOperand);
}
else if (loadOperand is int or long && fieldType.IsPrimitive)
{
// IL pushes integer constants as int32 (int64 after conv.i8) whatever the field's type. Without the cast,
// a ushort default reads as int, never Equals the typed value, and editors write it out as changed.
// Unchecked: the constant holds the field's bits (uint 3000000000 is pushed as -1294967296).
var bits = Convert.ToInt64(loadOperand);
defaultValue = Type.GetTypeCode(fieldType) switch
{
TypeCode.SByte => (object)unchecked((sbyte)bits),
TypeCode.Byte => unchecked((byte)bits),
TypeCode.Int16 => unchecked((short)bits),
TypeCode.UInt16 => unchecked((ushort)bits),
TypeCode.Int32 => unchecked((int)bits),
TypeCode.UInt32 => unchecked((uint)bits),
TypeCode.Int64 => bits,
TypeCode.UInt64 => unchecked((ulong)bits),
TypeCode.Char => unchecked((char)bits),
_ => loadOperand,
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Comment thread
Cleroth marked this conversation as resolved.
};
}
else
{
defaultValue = loadOperand;
Expand Down
Loading