Browse Source

#282 - Fix the casts in the other direction (from concrete type to type parameter).

pull/348/head
Daniel Grunwald 13 years ago
parent
commit
4906f3e26b
  1. 2
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 15
      ICSharpCode.Decompiler/Tests/Generics.cs

2
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -550,7 +550,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -550,7 +550,7 @@ namespace ICSharpCode.Decompiler.Ast
else
goto case ILCode.Castclass;
case ILCode.Castclass:
if (byteCode.Arguments[0].InferredType.IsGenericParameter)
if (byteCode.Arguments[0].InferredType.IsGenericParameter || ((Cecil.TypeReference)operand).IsGenericParameter)
return arg1.CastTo(new PrimitiveType("object")).CastTo(operandAsTypeRef);
else
return arg1.CastTo(operandAsTypeRef);

15
ICSharpCode.Decompiler/Tests/Generics.cs

@ -123,6 +123,11 @@ public static class Generics @@ -123,6 +123,11 @@ public static class Generics
return (string)((object)input);
}
public static T CastFromString<T>(string input)
{
return (T)((object)input);
}
public static bool IsInt<T>(T input)
{
return input is int;
@ -133,6 +138,11 @@ public static class Generics @@ -133,6 +138,11 @@ public static class Generics
return (int)((object)input);
}
public static T CastFromInt<T>(int input)
{
return (T)((object)input);
}
public static bool IsNullableInt<T>(T input)
{
return input is int?;
@ -147,4 +157,9 @@ public static class Generics @@ -147,4 +157,9 @@ public static class Generics
{
return (int?)((object)input);
}
public static T CastFromNullableInt<T>(int? input)
{
return (T)((object)input);
}
}

Loading…
Cancel
Save