This question already has answers here:
Serializing and Deserializing Expression Trees in C#
(7 answers)
Is it possible to dynamically compile and execute C# code fragments?
(7 answers)
Closed 7 years ago.
I wonder if it is possible to convert text to C# code for dynamic validation. For example, I'd love to be able to store a string in my DB like this:
((Value.StartsWith("CR") || Value.StartsWith("TRC")) && Value.Length == 10)
Then - pull it from the DB and use it to validate data. If would automatically swap out Value for the piece of data I'm trying to validate.
All validations would return a boolean that I would use in the code to see if the data being tested passed or failed.
I would have numerous variations of validations similar to the one above like this stored in my DB.
I've tried researching various phrases on Google but can't seem to think of what this might be called?
Related
This question already has answers here:
How to read values from the querystring with ASP.NET Core?
(14 answers)
Closed 3 years ago.
I'm trying to get a query string value using:
_httpContextAccessor.HttpContext.Request.QueryString["data"]
but it fails with error:
Cannot apply indexing with [] to an expression of type 'QueryString'
QueryString is from the Microsoft.AspNetCore.Http namespace.
Generally, you should rely on model-binding to access incoming values, not read them explicitly from a certain request source.
However, the correct way to read query-string values is through Request.Query instead. And in your case:
_httpContextAccessor.HttpContext.Request.Query["data"]
See Model-Binding
This question already has answers here:
How can I evaluate a C# expression dynamically?
(9 answers)
Closed 3 years ago.
So basically what i have been struggling with is to evaluate sentence in EF Core.
For example if i have:
string condition = "65 < 100 AND 65 > 50"
How can evaluate that?
You can execute SQL String in EF Core, So what you need is to write the whole SQL you want in a sctring and then concatenate this part to it. after that you execute it like this
myDbContextObject.Database.ExecuteSqlCommand(sqlString,params[]);
OR
myDbContextObject.Table.FromSql(sqlString,params[]);
This question already has answers here:
Evaluating string "3*(4+2)" yield int 18 [duplicate]
(13 answers)
Is there a string math evaluator in .NET?
(18 answers)
Closed 4 years ago.
I have one scenario in C#, which I fetch the expression from database, I need to parse and evaluate the same
The expression can be of any type (With + & - Operator only) as mentioned below
X+Y-Z
X-Y-Z
Z-Y+Z
Where as at run time I have any of above expression as string item and the values for each variable defined in it.
Now I need to automate the same, so that my code at run time will able to parse and evaluate the same.
I believe Switch case and if/else loop is the one way, but any can please suggest some other better and efficient way.
Thanks in advance
This question already has answers here:
C# Empty Statement
(13 answers)
Closed 5 years ago.
I've come across this example of an empty statement in a C# textbook.
Code:
public void empty()
{
;
}
Some quick googling found that it's a redundant feature and I can't see the use of this as it seems pointless?
I was curious to know when this would've been useful and if it's still used to date even though it's obsolete?
In the given example it is pointless and/or cosmetic.
The empty statement is "useful" in places where a statement is required but you have nothing to do, like
while (condition_with_side_effects) ;
Because of the side effects required, this will not match with most coding guidelines or best practices.
Consider it a leftover from C.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Is there a method that will evaluate a string and produce an integer (assuming the string is an equation) in C#
Hi all, i just wonder how to make a realtime complination in C#
For example: i have a string like this
string math = "1 + 2 + (4 - 6)";
And i want to complie it to get the result
How to do that? and is that the bad idea because i want to make a calculator in C#?
Edited:
The main question properly is that i want to do it in WP7, not exactly in C# windows lol, i tried all the solutions below but not at all is correct!
and is that the bad idea because i want to make a calculator in C#?
One problem with that is that your calculator language is probably supposed to be just a subset of C#. So using the C# compiler may be too flexible and allow arbitrary C#. Kind of like problems with SQL injection attacks.
Expresion Evalution is an application of STACK (Data Structure)
You can see these link If you want Sample projects
http://www.vbforums.com/showthread.php?t=397264
http://www.codeproject.com/KB/cs/runtime_eval.aspx
http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx