Browse Source

Fix #282: (T)(object)DateTime.Now; decompiles as (T)DateTime.Now;, which does not compile

pull/348/head
Daniel Grunwald 14 years ago
parent
commit
134c4515e4
  1. 7
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 40
      ICSharpCode.Decompiler/Tests/Generics.cs

7
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -543,12 +543,15 @@ namespace ICSharpCode.Decompiler.Ast @@ -543,12 +543,15 @@ namespace ICSharpCode.Decompiler.Ast
}
return arg1;
}
case ILCode.Castclass:
return arg1.CastTo(operandAsTypeRef);
case ILCode.Unbox_Any:
// unboxing does not require a cast if the argument was an isinst instruction
if (arg1 is AsExpression && byteCode.Arguments[0].Code == ILCode.Isinst && TypeAnalysis.IsSameType(operand as TypeReference, byteCode.Arguments[0].Operand as TypeReference))
return arg1;
else
goto case ILCode.Castclass;
case ILCode.Castclass:
if (byteCode.Arguments[0].InferredType.IsGenericParameter)
return arg1.CastTo(new PrimitiveType("object")).CastTo(operandAsTypeRef);
else
return arg1.CastTo(operandAsTypeRef);
case ILCode.Isinst:

40
ICSharpCode.Decompiler/Tests/Generics.cs

@ -107,4 +107,44 @@ public static class Generics @@ -107,4 +107,44 @@ public static class Generics
// Tests references to inner classes in generic classes
return d.Keys.GetEnumerator();
}
public static bool IsString<T>(T input)
{
return input is string;
}
public static string AsString<T>(T input)
{
return input as string;
}
public static string CastToString<T>(T input)
{
return (string)((object)input);
}
public static bool IsInt<T>(T input)
{
return input is int;
}
public static int CastToInt<T>(T input)
{
return (int)((object)input);
}
public static bool IsNullableInt<T>(T input)
{
return input is int?;
}
public static int? AsNullableInt<T>(T input)
{
return input as int?;
}
public static int? CastToNullableInt<T>(T input)
{
return (int?)((object)input);
}
}

Loading…
Cancel
Save