diff --git a/Mono.Cecil/FieldDefinition.cs b/Mono.Cecil/FieldDefinition.cs index 15b7720c3..7ce8d27b5 100644 --- a/Mono.Cecil/FieldDefinition.cs +++ b/Mono.Cecil/FieldDefinition.cs @@ -113,6 +113,7 @@ public byte [] InitialValue { } set { initial_value = value; + HasFieldRVA = !initial_value.IsNullOrEmpty (); rva = 0; } } @@ -245,6 +246,11 @@ public bool HasDefault { set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.HasDefault, value); } } + public bool HasFieldRVA { + get { return attributes.GetAttributes ((ushort) FieldAttributes.HasFieldRVA); } + set { attributes = attributes.SetAttributes ((ushort) FieldAttributes.HasFieldRVA, value); } + } + #endregion public override bool IsDefinition { diff --git a/Test/Mono.Cecil.Tests/FieldTests.cs b/Test/Mono.Cecil.Tests/FieldTests.cs index 05165d692..4f575de6e 100644 --- a/Test/Mono.Cecil.Tests/FieldTests.cs +++ b/Test/Mono.Cecil.Tests/FieldTests.cs @@ -122,6 +122,14 @@ public void FieldRVA () Assert.AreEqual (2, buffer.ReadUInt32 ()); Assert.AreEqual (3, buffer.ReadUInt32 ()); Assert.AreEqual (4, buffer.ReadUInt32 ()); + + var intialValue = field.InitialValue; + field.InitialValue = null; + Assert.False (field.Attributes.HasFlag (FieldAttributes.HasFieldRVA)); + + field.InitialValue = intialValue; + + Assert.True (field.Attributes.HasFlag (FieldAttributes.HasFieldRVA)); }); }