/
Emit.InitializeObject.cs
44 lines (39 loc) · 1.41 KB
/
Emit.InitializeObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Sigil.Impl;
using System;
using System.Reflection.Emit;
namespace Sigil
{
public partial class Emit<DelegateType>
{
/// <summary>
/// Expects an instance of the type to be initialized on the stack.
///
/// Initializes all the fields on a value type to null or an appropriate zero value.
/// </summary>
public Emit<DelegateType> InitializeObject<ValueType>()
{
return InitializeObject(typeof(ValueType));
}
/// <summary>
/// Expects an instance of the type to be initialized on the stack.
///
/// Initializes all the fields on a value type to null or an appropriate zero value.
/// </summary>
public Emit<DelegateType> InitializeObject(Type valueType)
{
if (valueType == null)
{
throw new ArgumentNullException("valueType");
}
var transitions =
new[]
{
new StackTransition(new [] { typeof(NativeIntType) }, Type.EmptyTypes),
new StackTransition(new [] { valueType.MakePointerType() }, Type.EmptyTypes),
new StackTransition(new [] { valueType.MakeByRefType() }, Type.EmptyTypes),
};
UpdateState(OpCodes.Initobj, valueType, Wrap(transitions, "InitializeObject"));
return this;
}
}
}