Browse Source

Display type information of fixed fields as "Type[Length]" in tree view.

pull/1505/head
Siegfried Pammer 6 years ago
parent
commit
2e00285666
  1. 21
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 8
      ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs
  3. 8
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

21
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1406,6 +1406,27 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1406,6 +1406,27 @@ namespace ICSharpCode.Decompiler.CSharp
return false;
}
internal static bool IsFixedField(MetadataReader metadata, FieldDefinitionHandle handle, out IType type, out int elementCount)
{
type = null;
elementCount = 0;
var field = metadata.GetFieldDefinition(handle);
foreach (var h in field.GetCustomAttributes()) {
var customAttribute = metadata.GetCustomAttribute(h);
if (customAttribute.IsKnownAttribute(metadata, KnownAttribute.FixedBuffer)) {
var value = customAttribute.DecodeValue(MetadataExtensions.minimalCorlibTypeProvider);
if (value.FixedArguments.Length == 2) {
if (value.FixedArguments[0].Value is IType trr && value.FixedArguments[1].Value is int length) {
type = trr;
elementCount = length;
return true;
}
}
}
}
return false;
}
EntityDeclaration DoDecompile(IProperty property, DecompileRun decompileRun, ITypeResolveContext decompilationContext)
{
Debug.Assert(decompilationContext.CurrentMember == property);

8
ICSharpCode.Decompiler/CSharp/OutputVisitor/CSharpAmbience.cs

@ -137,7 +137,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -137,7 +137,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
writer.Space();
writer.WriteToken(Roles.Colon, ":");
writer.Space();
rt.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
if (symbol is IField f && CSharpDecompiler.IsFixedField(f.ParentModule.PEFile.Metadata, (System.Reflection.Metadata.FieldDefinitionHandle)f.MetadataToken, out var type, out int elementCount)) {
rt = astBuilder.ConvertType(type);
new IndexerExpression(new TypeReferenceExpression(rt), astBuilder.ConvertConstantValue(f.Compilation.FindType(KnownTypeCode.Int32), elementCount))
.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
} else {
rt.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
}
}
}

8
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -176,25 +176,25 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax @@ -176,25 +176,25 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public bool UseCustomEvents { get; set; }
/// <summary>
/// Controls if unbound type argument names are inserted in the ast or not.
/// Controls whether unbound type argument names are inserted in the ast or not.
/// The default value is <c>false</c>.
/// </summary>
public bool ConvertUnboundTypeArguments { get; set;}
/// <summary>
/// Controls if aliases should be used inside the type name or not.
/// Controls whether aliases should be used inside the type name or not.
/// The default value is <c>true</c>.
/// </summary>
public bool UseAliases { get; set; }
/// <summary>
/// Controls if constants like <c>int.MaxValue</c> are converted to a <see cref="MemberReferenceExpression"/> or <see cref="PrimitiveExpression" />.
/// Controls whether constants like <c>int.MaxValue</c> are converted to a <see cref="MemberReferenceExpression"/> or <see cref="PrimitiveExpression" />.
/// The default value is <c>true</c>.
/// </summary>
public bool UseSpecialConstants { get; set; }
/// <summary>
/// Controls if integral constants should be printed in hexadecimal format.
/// Controls whether integral constants should be printed in hexadecimal format.
/// The default value is <c>false</c>.
/// </summary>
public bool PrintIntegralValuesAsHex { get; set; }

Loading…
Cancel
Save