csharp-eval-unity3d icon indicating copy to clipboard operation
csharp-eval-unity3d copied to clipboard

return void, set field value

Open friuns2 opened this issue 8 years ago • 9 comments

does it support any those?

var typeResolver = new KnownTypeResolver(typeof(Test), typeof(Console));
var test = new Test();
var exprTree = CSharpExpression.Evaluate<Test,int>("test.te=23", test,typeResolver:typeResolver);
throws error Unexpected symbol '='

var exprTree = CSharpExpression.Evaluate<System.void>("Console.Write(123)",typeResolver:typeResolver);
will not work because cannot use System.void

friuns2 avatar Jul 22 '17 01:07 friuns2

Hi. It is only support expressions. "a=b" is a statement.

"void" returning expressions currently are not supported too. I know it will be bit ugly, but you can wrap "Write" with your method which return something.

Mutation could be done with methods - "test.SetValue(23)"

deniszykov avatar Jul 23 '17 21:07 deniszykov

ok thanks, too bad statements would be usefull :)

friuns2 avatar Jul 25 '17 13:07 friuns2

I really need this feature, so before I dig into the code to figure out how to add it, is there a strong reason why this is not supported? Thanks!

catdawg avatar Nov 29 '17 13:11 catdawg

I really need this feature

Which one?

  1. Action expressions (void return type)
  2. Statements

deniszykov avatar Nov 29 '17 15:11 deniszykov

Sorry should have been clearer 😅 the void expressions.

catdawg avatar Nov 29 '17 15:11 catdawg

Actually not much. New methods for CSharpExpression a few changes in Binder and AotCompiler. I could try to implement it tomorrow.

On the other hand, statements is a huge feature and in the near future I do not plan to implement it.

deniszykov avatar Nov 29 '17 16:11 deniszykov

If you could implement this, I would be extremely likely to use your lib :) Thanks for the fast responses btw!

catdawg avatar Nov 30 '17 14:11 catdawg

I have updated NuGet package to version 2.2.0 where Action delegates are supported. Or you could build from sources 4c49d86600db8ead99c21bc2debdbd4dcbf1aa1c. Or wait for Unity Asset Store update.

deniszykov avatar Nov 30 '17 18:11 deniszykov

Cool! I'll try it out, thanks!

catdawg avatar Dec 01 '17 10:12 catdawg