Permalink
Browse files

Fix #1394: Fields marked 'specialname' are excluded from the type system

  • Loading branch information...
siegfriedpammer committed Jan 26, 2019
1 parent deeb603 commit 9d19b33ec0e8f9ad83738f42afabe54d419114a8
@@ -488,9 +488,17 @@ public void EnumTest()
public void EnumFieldsTest()
{
var e = GetTypeDefinition(typeof(MyEnum));
IField[] fields = e.Fields.ToArray();
IField valueField = e.Fields.First();
IField[] fields = e.Fields.Skip(1).ToArray();
Assert.AreEqual(5, fields.Length);

Assert.AreEqual("value__", valueField.Name);
Assert.AreEqual(GetTypeDefinition(typeof(short)), valueField.Type);
Assert.AreEqual(Accessibility.Public, valueField.Accessibility);
Assert.AreEqual(null, valueField.GetConstantValue());
Assert.IsFalse(valueField.IsConst);
Assert.IsFalse(valueField.IsStatic);

foreach (IField f in fields) {
Assert.IsTrue(f.IsStatic);
Assert.IsTrue(f.IsConst);
@@ -951,6 +951,8 @@ EntityDeclaration DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun
}
foreach (var field in typeDef.Fields) {
if (!field.MetadataToken.IsNil && !MemberIsHidden(module.PEFile, field.MetadataToken, settings)) {
if (typeDef.Kind == TypeKind.Enum && !field.IsConst)
continue;
var memberDecl = DoDecompile(field, decompileRun, decompilationContext.WithCurrentMember(field));
typeDecl.Members.Add(memberDecl);
}
@@ -1262,7 +1264,7 @@ EntityDeclaration DoDecompile(IField field, DecompileRun decompileRun, ITypeReso
Debug.Assert(decompilationContext.CurrentMember == field);
try {
var typeSystemAstBuilder = CreateAstBuilder(decompilationContext);
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum) {
if (decompilationContext.CurrentTypeDefinition.Kind == TypeKind.Enum && field.IsConst) {
var enumDec = new EnumMemberDeclaration { Name = field.Name };
object constantValue = field.GetConstantValue();
if (constantValue != null) {
@@ -162,7 +162,7 @@ public override string ToString()
foreach (FieldDefinitionHandle h in fieldCollection) {
var field = metadata.GetFieldDefinition(h);
var attr = field.Attributes;
if (module.IsVisible(attr) && (attr & FieldAttributes.SpecialName) == 0) {
if (module.IsVisible(attr)) {
fieldList.Add(module.GetDefinition(h));
}
}
@@ -79,10 +79,16 @@ protected override void LoadChildren()
foreach (var nestedType in TypeDefinition.NestedTypes.OrderBy(t => t.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new TypeTreeNode(nestedType, ParentAssemblyNode));
}
foreach (var field in TypeDefinition.Fields.OrderBy(f => f.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new FieldTreeNode(field));
if (TypeDefinition.Kind == TypeKind.Enum) {
// if the type is an enum, it's better to not sort by field name.
foreach (var field in TypeDefinition.Fields) {
this.Children.Add(new FieldTreeNode(field));
}
} else {
foreach (var field in TypeDefinition.Fields.OrderBy(f => f.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new FieldTreeNode(field));
}
}

foreach (var property in TypeDefinition.Properties.OrderBy(p => p.Name, NaturalStringComparer.Instance)) {
this.Children.Add(new PropertyTreeNode(property));
}

0 comments on commit 9d19b33

Please sign in to comment.