Comments (7)
Hello, thanks for the bug report and pull request.
Until now, I never used struct with ExpressionEvaluator only classes.
So there are probably some others bugs linked to that.
I will integrate your correction to next release and start some tests about the use of structs
from expressionevaluator.
I did some tests with structs;
Your pull request correct the specific bug you reported thanks for that.
But for now I struggling with this. As struct are ValueType and are copied when given to methods and as ExpressionEvaluator use reflection (methods) to assign fields and properties, some weird things happend when you imbricate structs for example.
When you assign a value in a sub struct, the struct is copied and the assignation is never reported in the struct hierarchy.
// Set 3 on a copy of the struct2
struct1.struct2.x = 3
// This will not return 3
return struct1.struct2.x;
I will make more investigations. But for now be careful when using struct with ExpressionEvaluator.
from expressionevaluator.
I see. : \ I spent some time digging through the code, to find a solution. I think the only way around it is that in case of a value assing we have to trace back and set every field value to the new copies.
So in your example first struct2.x = 3 (which creates a 'new struct2') then struct1.struct2 = 'new struct2'.
This would solve the problem with value types and wouldn't cause problems with reference types as you would just re-set the references.
Unfortunatelly, I don't trivially see how to achieve this in your code.
from expressionevaluator.
Yes you are right I came to the same kind of solution trace the assignation path.
I just need now to find the way to implement it.
from expressionevaluator.
I will try it these next couple of days.
from expressionevaluator.
OK I found a way to manage this.
All is done this tiny class
private class ValueTypeNestingTrace
{
public object Container { get; set; }
public MemberInfo Member { get; set; }
public object Value { get; set; }
public void AssignValue()
{
if (Container is ValueTypeNestingTrace valueTypeNestingTrace)
{
((dynamic)Member).SetValue(valueTypeNestingTrace.Value, Value);
valueTypeNestingTrace.AssignValue();
}
else
{
((dynamic)Member).SetValue(Container, Value);
}
}
}
And some small modifications in the method EvaluateVarOrFunc
I did some tests and actually it works better than C# when doing something like :
classContainer = new ClassContainer()
{
NestedStructProperty = new StructForTest1()
{
myIntvalue = 8,
myStringValue = "Test"
}
};
// Do not compile In C#
classContainer.NestedStructProperty.myIntvalue = 9;
// Return : Test 9
return $"Result {classContainer.NestedStructProperty.myStringValue} {classContainer.NestedStructProperty.myIntvalue}";
I don't know if it should be more like C# or if it is better like this
Maybe I will add an option later to choose if this specific case must throw an exception.
For now I will integrate it as this in the next version
from expressionevaluator.
Just published v : 1.3.7.0
from expressionevaluator.
Related Issues (20)
- Add an option to disallow accessing namespaces HOT 2
- Referencing property of property can cause unwanted exception
- Syntax error of sign symbols
- Intelligente type casting
- Error message - Exception has been thrown by the target of an invocation. HOT 3
- Linq Select throws exception (ValueTuple?) issue? HOT 3
- Syntax error in Functions HOT 3
- Incorrect result. HOT 1
- Strong name HOT 1
- Ignore missing zero in numeric values
- Match function arguments considering implicit casts HOT 2
- Decimal support for math functions
- Slow EvaluateCast HOT 1
- Syntax error calling overloaded method in context object including Func<> parameter
- Link error in Unity Android il2cpp build
- Can't handle division HOT 2
- [Suggestion] AssignVariable in Script Evaluation (Not in Declraration)
- Doesn't process a IDictionary<string, object> correctly.
- Is it possible to add an operator that is both right-hand-side-only and can act as a normal one? HOT 2
- RobiniaDocs API Explorer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expressionevaluator.