Browse Source

Handle calls to value type constructors. Closes #66.

pull/70/head
Daniel Grunwald 14 years ago
parent
commit
5078d2ef89
  1. 10
      ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs
  2. 2
      ICSharpCode.Decompiler/DecompilerSettings.cs
  3. 16
      ICSharpCode.Decompiler/Tests/ValueTypes.cs

10
ICSharpCode.Decompiler/Ast/AstMethodBodyBuilder.cs

@ -535,6 +535,16 @@ namespace ICSharpCode.Decompiler.Ast @@ -535,6 +535,16 @@ namespace ICSharpCode.Decompiler.Ast
}
}
if (cecilMethod.Name == ".ctor" && cecilMethod.DeclaringType.IsValueType) {
// On value types, the constructor can be called.
// This is equivalent to 'target = new ValueType(args);'.
ObjectCreateExpression oce = new ObjectCreateExpression();
oce.Type = AstBuilder.ConvertType(cecilMethod.DeclaringType);
AdjustArgumentsForMethodCall(cecilMethod, methodArgs);
oce.Arguments.AddRange(methodArgs);
return new AssignmentExpression(target, oce);
}
if (cecilMethod.Name == "Get" && cecilMethod.DeclaringType is ArrayType && methodArgs.Count > 1) {
return target.Indexer(methodArgs);
} else if (cecilMethod.Name == "Set" && cecilMethod.DeclaringType is ArrayType && methodArgs.Count > 2) {

2
ICSharpCode.Decompiler/DecompilerSettings.cs

@ -41,8 +41,6 @@ namespace ICSharpCode.Decompiler @@ -41,8 +41,6 @@ namespace ICSharpCode.Decompiler
}
}
public event EventHandler YieldReturnChanged;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)

16
ICSharpCode.Decompiler/Tests/ValueTypes.cs

@ -9,6 +9,11 @@ public static class ValueTypes @@ -9,6 +9,11 @@ public static class ValueTypes
{
public int Field;
public S(int field)
{
this.Field = field;
}
public void SetField()
{
this.Field = 5;
@ -46,6 +51,17 @@ public static class ValueTypes @@ -46,6 +51,17 @@ public static class ValueTypes
p = default(S);
}
public static S CallValueTypeCtor1()
{
return new S(10);
}
public static S CallValueTypeCtor2()
{
S s = new S(10);
return s;
}
public static S Copy1(S p)
{
return p;

Loading…
Cancel
Save