thorgeirk11 / REX-Diagnostics

Unity extension that enables expression evaluation at runtime to facilitate testing and debugging.
MIT License
95 stars 7 forks source link

private variable support? #16

Open friuns2 opened 6 years ago

friuns2 commented 6 years ago

When i try to access private variable T-Rex throws error https://i.imgur.com/OwJUjuk.png

how can i access private variable?

thorgeirk11 commented 6 years ago

Unfortunately Rex is unable to do this.

This is due to the way Rex creates the compiled scripts. There are two seperate parts to Rex, first there is the code compleation which uses reflection to find the avilable functions and properties of a given type. The secound is the compaliation of the expression provied.

For exampe the code Selection.activeContext gets translated into a body like so:

using System;
using System.Linq;
using UnityEditor;
using UnityEngine;

class __TempRexClass
{
    public Func<object> Func() 
    { 
        return new Func<object>(() => Selection.activeContext);
    }
}

Which is compiled and then executed. Note this snipit of code has the same ristrictions as any other when it comes to private variables.


Workaround is to change the member to public while debuging and change it back once done.

I could be more smart about using reflection to acess the values for a given expression.

friuns2 commented 5 years ago

Hi i found something, there is c# interpreter on github called SlowSharp, if you run scripts with it and you need modify its source code so bool IsAcceesible returning always true

https://github.com/pjc0247/SlowSharp/blob/a48e772b0681218912c9014d0d4ed894fd437148/Slowsharp/Runtime/AccessModifier.cs

i tested it with accessing private variable and it did work