Skip to content

Commit dc3031f

Browse files
committed
Update
1 parent 9c9c4ac commit dc3031f

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

src/Tests/StructTest/StructTest.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ public static void Complex_Test()
1313
{
1414
var r = new Result<BaseError>(new BaseError(11, null, null));
1515
TypeLayout.PrintLayout(r.GetType(), true);
16+
//Type layout for 'Result`1'
17+
//Size: 32 bytes. Paddings: 11 bytes (%34 of empty space)
18+
//|==========================================|
19+
//| 0: Boolean _hasError (1 byte) |
20+
//|------------------------------------------|
21+
//| 1-7: padding (7 bytes) |
22+
//|------------------------------------------|
23+
//| 8-31: BaseError _error (24 bytes) |
24+
//| |======================================| |
25+
//| | 0-7: Exception Exception (8 bytes) | |
26+
//| |--------------------------------------| |
27+
//| | 8-15: String Reason (8 bytes) | |
28+
//| |--------------------------------------| |
29+
//| | 16-19: Int32 Code (4 bytes) | |
30+
//| |--------------------------------------| |
31+
//| | 20-23: padding (4 bytes) | |
32+
//| |======================================| |
33+
//|==========================================|
1634
}
1735

1836
public static void Simple_Test()
@@ -107,7 +125,7 @@ public InnerStruct(int intField, bool boolField)
107125

108126
#region Complex
109127

110-
[StructLayout(LayoutKind.Auto, Pack = 1)]
128+
[StructLayout(LayoutKind.Auto)]
111129
//[StructLayout(LayoutKind.Sequential, Pack = 1)]
112130
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>")]
113131
public readonly record struct Result<TError>
@@ -139,28 +157,33 @@ public Result(in TError error)
139157
}
140158
}
141159

142-
[StructLayout(LayoutKind.Auto, Pack = 1)]
160+
[StructLayout(LayoutKind.Auto)]
143161
//[StructLayout(LayoutKind.Sequential, Pack = 1)]
144162
public readonly record struct BaseError
145163
{
146-
public readonly int Code;
164+
public BaseError(int code, Exception? exception, string? reason)
165+
{
166+
Code = code;
167+
//Exception = exception;
168+
//Reason = reason;
169+
}
170+
171+
#region Properties
172+
173+
public readonly int Code { get; }
147174

148175
/// <summary>
149176
/// Gets the exception.
150177
/// </summary>
151-
public readonly Exception? Exception;
178+
public readonly Exception? Exception { get; }
152179

153180
/// <summary>
154181
/// Gets the reason.
155182
/// </summary>
156-
public readonly string? Reason;
183+
public readonly string? Reason { get; }
184+
185+
#endregion
157186

158-
public BaseError(int code, Exception? exception, string? reason)
159-
{
160-
Code = code;
161-
//Exception = exception;
162-
Reason = reason;
163-
}
164187
}
165188

166189
#endregion

0 commit comments

Comments
 (0)