Trouble compiling some decompiled C# code

Posted by Colin O'Dell on Stack Overflow See other posts from Stack Overflow or by Colin O'Dell
Published on 2010-12-24T15:45:13Z Indexed on 2010/12/24 15:54 UTC
Read the original article Hit count: 234

Filed under:
|
|
|

I was decompiling an open-source project (because the source for the latest version hasn't been released yet). Using RedGate's Reflector tool, it gave me this block of code:

if(somecondition == true)
{
    ref Vector3i vectoriRef;
    float num17 = length - num;
    Vector3i end = vectori3;
    (vectoriRef = (Vector3i) &end)[1] = vectoriRef[1] - ((int) num17);
}

somecondition is a boolean. length and num are floats defined outside the code. vectori3 is also defined outside the code and is of type Vector3i. The type Vector3i is essentially this code, but with x, y, and z stored as integers.

When I try to compile this decompiled code, I get the following errors:

  • Line 2: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
  • Line 3: ; expected
  • Line 3: Invalid expression term 'ref'
  • Line 6: 'Vector3i' is a 'type' but is used like a 'variable'

Any thoughts on how I can fix this code so it compiles correctly and does whatever it was intended to do?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET