Browse Source

Fix #856: fix decompilation of attributes where null is passed to a parameter of type System.Type.

pull/863/head
Daniel Grunwald 8 years ago
parent
commit
c40ba690bc
  1. 17
      ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs
  2. 16
      ICSharpCode.Decompiler/TypeSystem/Implementation/BlobReader.cs

17
ICSharpCode.Decompiler.Tests/CustomAttributes/S_CustomAttributes.cs

@ -42,8 +42,25 @@ namespace aa @@ -42,8 +42,25 @@ namespace aa
[My(ULongEnum.MaxUInt64)]
public enum ULongEnum : ulong
{
[My(null)]
MaxUInt64 = 18446744073709551615uL
}
[AttributeUsage(AttributeTargets.Class)]
public class TypesAttribute : Attribute
{
public TypesAttribute(Type type)
{
}
}
[Types(typeof(int))]
private class Class1
{
}
[Types(null)]
private class Class2
{
}
[My(EnumWithFlag.Item1 | EnumWithFlag.Item2)]
private static int field;
[My(EnumWithFlag.All)]

16
ICSharpCode.Decompiler/TypeSystem/Implementation/BlobReader.cs

@ -237,7 +237,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -237,7 +237,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
else
return new ConversionResolveResult(elementType, elem, Conversion.BoxingConversion);
} else if (typeCode == KnownTypeCode.Type) {
return new TypeOfResolveResult(underlyingType, ReadType());
var type = ReadType();
if (type != null) {
return new TypeOfResolveResult(underlyingType, type);
} else {
return new ConstantResolveResult(underlyingType, null);
}
} else {
return new ConstantResolveResult(elementType, ReadElemValue(typeCode));
}
@ -360,7 +365,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -360,7 +365,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
case 0x51: // boxed value type
return compilation.FindType(KnownTypeCode.Object);
case 0x55: // enum
return ReadType();
var type = ReadType();
if (type == null) {
throw new NotSupportedException("Enum type should not be null.");
}
return type;
default:
throw new NotSupportedException(string.Format("Custom attribute type 0x{0:x} is not supported.", b));
}
@ -369,6 +378,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -369,6 +378,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IType ReadType()
{
string typeName = ReadSerString();
if (typeName == null) {
return null;
}
ITypeReference typeReference = ReflectionHelper.ParseReflectionName(typeName);
IType typeInCurrentAssembly = typeReference.Resolve(new SimpleTypeResolveContext(currentResolvedAssembly));
if (typeInCurrentAssembly.Kind != TypeKind.Unknown)

Loading…
Cancel
Save