Re: Type convertsion from string



How to call static methods from ADO.NET expressions ?
You can't ;-p
You could write, buy, beg or borrow a parser that handles what you
need. A quick search reveals USPExpress Math Parser (unisoftplus),
MathExpParses (c-sharpcorner), Math Parser (bestcode), etc. Perhaps
look into these as a means to achieving your goal.

An interesting (to me) aside: if your release schedule allows, you
could also look at the DynamicQuery code from the VS 2008 samples page
on MSDN2; this is an expression parser that can read simple LINQ-style
queries and supports a few operators - but not many. The Expression
can be compiled to a delegate, for instance for invoke by a runtime
property (via something like TypeDescriptionProvider). It doesn't
support any of the Math.Whatever() methods, but it might serve as
inspiration... Or maybe I'm trying to use LINQ to solve everything at
the moment ;-p

2. Before first access to every entity object application creates
entity class (.cs file) from table structure in database and adds
expressions as properties to this file.
Warning: compiling input at runtime (and executing it) is risky unless
you really trust the source; it is very easy to insert malicious code
into a formula. Just be incredibly careful! You could white-list
approved methods, but even then parsing the expression (to check) can
be a pain...

To get this working, and to allow *some* kind of compile-time
type-safety, you'd need to use some kind of factory model, i.e.
---core code---
public abstract class SomeEntity {
public string Name {...} /// "regular" methods
public int Whatever {...}
static SomeEntity Create() {
... compiles if necessary, and returns a new SomeEntityImp()
}
}
---compile template---
public class SomeEntityImp : SomeEntity {
// ... additional properties (formulae) get inserted here
}

Is this best solution ?
I don't think either is very ideal; and either could be abused... all
it needs is somebody to create a recursive expression (or do something
super-super-exponential), and *boom*. This is quite


.


Loading