Skip to content

Commit

Permalink
Implement automatic handling of the HasFieldRVA field attribute. (#733)
Browse files Browse the repository at this point in the history
* Implement automatic handling of the HasFieldRVA field attribute.

Fixes #728

* Add FieldDefinition.HasFieldRVA

Co-authored-by: Jb Evain <[email protected]>
  • Loading branch information
jkoritzinsky and jbevain authored Mar 16, 2021
1 parent 553506a commit f3ec06a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Mono.Cecil/FieldDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public byte [] InitialValue {
}
set {
initial_value = value;
HasFieldRVA = !initial_value.IsNullOrEmpty ();
rva = 0;
}
}
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions Test/Mono.Cecil.Tests/FieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down

0 comments on commit f3ec06a

Please sign in to comment.