Skip to content

Commit f3ec06a

Browse files
jkoritzinskyjbevain
andauthoredMar 16, 2021
Implement automatic handling of the HasFieldRVA field attribute. (jbevain#733)
* Implement automatic handling of the HasFieldRVA field attribute. Fixes jbevain#728 * Add FieldDefinition.HasFieldRVA Co-authored-by: Jb Evain <jb@evain.net>
1 parent 553506a commit f3ec06a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

‎Mono.Cecil/FieldDefinition.cs

+6
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public byte [] InitialValue {
113113
}
114114
set {
115115
initial_value = value;
116+
HasFieldRVA = !initial_value.IsNullOrEmpty ();
116117
rva = 0;
117118
}
118119
}
@@ -245,6 +246,11 @@ public bool HasDefault {
245246
set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.HasDefault, value); }
246247
}
247248

249+
public bool HasFieldRVA {
250+
get { return attributes.GetAttributes ((ushort) FieldAttributes.HasFieldRVA); }
251+
set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.HasFieldRVA, value); }
252+
}
253+
248254
#endregion
249255

250256
public override bool IsDefinition {

‎Test/Mono.Cecil.Tests/FieldTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ public void FieldRVA ()
122122
Assert.AreEqual (2, buffer.ReadUInt32 ());
123123
Assert.AreEqual (3, buffer.ReadUInt32 ());
124124
Assert.AreEqual (4, buffer.ReadUInt32 ());
125+
126+
var intialValue = field.InitialValue;
127+
field.InitialValue = null;
128+
Assert.False (field.Attributes.HasFlag (FieldAttributes.HasFieldRVA));
129+
130+
field.InitialValue = intialValue;
131+
132+
Assert.True (field.Attributes.HasFlag (FieldAttributes.HasFieldRVA));
125133
});
126134
}
127135

0 commit comments

Comments
 (0)