-
-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException using variables in custom functions #284
Comments
I forgot to mention, I appreciate the interpreter doesn’t know not to deference CUST1 and so hence the exception. My question is, is it possible somehow to implement such an IF function? If not, then how would we write an if block? I know we could use a ternary operator but I’m trying to avoid my users having to use that. |
Adding the relavant code here:
|
The problem is that the parameter is evaluated always, it is not dependent on the condition. Why not using the standard
|
Many thanks for your prompt response @davideicardi. As mentioned in my comment, we could use the ternary operator but the reason being our end users are much more familiar with Excel style functions. I guess it's asking a bit much for the interpreter to understand the desired IF function, which I appreciate. Is it at all possible to write an if/else statement? My users would understand this more. I have tried but do not seem to get it to work. |
Writing an |
You may need it https://github.com/ncalc/ncalc |
We have a use case where we are defining our own custom IF function and then making use of it using an expression like so:
IF(CUST1 != null, CUST1.Name, "Cust1 is null")
The problem we are facing is when the CUST1 variable turns out to be a null instance then we get a null reference exception when we call Interpreter.Eval for the expression.
Here's the complete code:
I've also attached the .cs file for it as a .txt file since I don't seem to be able to attach .cs files directly. See Tester.txt.
Tester.txt
The text was updated successfully, but these errors were encountered: