Я боюсь, что ответ отрицательный, как вы его написали. Функция, которую вы показываете, использует функцию DataColumn в таблицах данных, свойство Expression.
эффективно, она поддерживает многие из операторов вы бы найти в SQL:
Из документации:
OPERATORS
Concatenation is allowed using Boolean AND, OR, and NOT operators. You can use parentheses to group clauses and force precedence. The AND operator has precedence over other operators. For example:
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'
When creating comparison expressions, the following operators are allowed:
<
>
<=
>=
<>
=
IN
LIKE
The following arithmetic operators are also supported in expressions:
+ (addition)
- (subtraction)
* (multiplication)
/(division)
% (modulus)
STRING OPERATORS
To concatenate a string, use the + character. Whether string comparisons are case-sensitive or not is determined by the value of the DataSet class's CaseSensitive property. However, you can override that value with the DataTable class's CaseSensitive property.
WILDCARD CHARACTERS
Both the * and % can be used interchangeably for wildcards in a LIKE comparison. If the string in a LIKE clause contains a * or %, those characters should be escaped in brackets ([]). If a bracket is in the clause, the bracket characters should be escaped in brackets (for example [[] or []]). A wildcard is allowed at the beginning and end of a pattern, or at the end of a pattern, or at the beginning of a pattern. For example:
"ItemName LIKE '*product*'"
"ItemName LIKE '*product'"
"ItemName LIKE 'product*'"
Wildcards are not allowed in the middle of a string. For example, 'te*xt' is not allowed.
PARENT/CHILD RELATION REFERENCING
A parent table may be referenced in an expression by prepending the column name with Parent. For example, the Parent.Price references the parent table's column named Price.
A column in a child table may be referenced in an expression by prepending the column name with Child. However, because child relationships may return multiple rows, you must include the reference to the child column in an aggregate function. For example, Sum(Child.Price) would return the sum of the column named Price in the child table.
If a table has more than one child, the syntax is: Child(RelationName). For example, if a table has two child tables named Customers and Orders, and the DataRelation object is named Customers2Orders, the reference would be:
Avg(Child(Customers2Orders).Quantity)
AGGREGATES
The following aggregate types are supported:
Sum (Sum)
Avg (Average)
Min (Minimum)
Max (Maximum)
Count (Count)
StDev (Statistical standard deviation)
Var (Statistical variance).
Aggregates are usually performed along relationships. Create an aggregate expression by using one of the functions listed above and a child table column as detailed in PARENT/CHILD RELATION REFERENCING above. For example:
Avg(Child.Price)
Avg(Child(Orders2Details).Price)
К сожалению, квадратный корень не одна из функций, которые вы можете использовать. Однако, поскольку вы используете DataTable, вы можете просто перебирать строки и вычислять SquareRoot непосредственно из значения столбца. Представьте, что у вас есть столбец под названием «MyNumber». Вы могли бы сделать что-то вроде:
myDataTable.Columns.Add(new DataColumn() { Name = "MySquareRoot", DataType = typeof(Double)});
foreach(DataRow row in myDataTable.Rows)
{
myDataTable["MySquareRoot"] = Math.Sqrt(Convert.ToDouble(myDataTable["MyNumber"]));
}
Вы могли бы поставить такую функцию в Extension метод, если вы хотите.
В качестве альтернативы вы можете обращаться с вашими формулами где-то в другом месте; вместо использования DataTable для моделирования ваших данных, вы можете использовать класс. Сам класс может иметь свойства (или список или коллекцию), которые представляют ваши данные, и методы, действующие на ваши данные, - тогда вы можете использовать любую функцию, которую вы хотите на C#.
Что именно вы используете 'из Интернета где-то'? – Randy
Я не совсем уверен, что вы просите. Если вы имеете в виду, где я его получил, я получил это с форума, подобного этому, отвечая на вопрос о способности разбирать строковые уравнения. Если вы спрашиваете, для чего я его использую, это для проекта, который у меня есть в школе. Нам нужно проанализировать формулу, извлекаемую из базы данных. – Cityonhill93
Вместо 'string.Empty.GetType() 'вы можете написать' typeof (string) '. –