|
Sander Rossel wrote: My coworker was like, "I could write a parser and spend a few days, or I can do it like this and be done with it
I can write an expression parser in about a day, but it would take forever to test
Sander Rossel wrote: I did find some smart guy who just compiled a string using reflection (using ICodeCompiler.CompileAssemblyFromSource) and then simply invokes it
I actually considered that approach. Or using Roslyn.
I think I'll avoid the Eval function, wherever it is. It probably compiles code anyway.
Real programmers use butterflies
|
|
|
|
|
|
Sander Rossel wrote: So to hell with unit tests and back to some good old manual testing and praying for the best
That's the spirit! Liberating isn't it? What's a good program without a few bugs anyway?
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: What's a good program without a few bugs anyway? A very short program
|
|
|
|
|
CS0030 Cannot convert type 'string' to 'System.Linq.Expressions.Expression'
|
|
|
|
|
Yes.
That was a joke, there's no way a string can simply be cast to an Expression
|
|
|
|
|
|
|
That was my plan, but before I did it I wanted to see if it was done.
My parser spits out CodeDOM constructs, so it needs some retooling to work with expressions.
Real programmers use butterflies
|
|
|
|
|
So not sure if this is what your looking for but I used the System.Linq.Expressions namespace
to build a dynamic link query to be executed against EF.
here is an incomplete sample for syntax example:
propertyToUse = workingProperty.Substring(0, workingProperty.IndexOf('.'));
Type propertyToUseType = GetEntityType(propertyToUse, incomingParentType);
ParameterExpression propertyToUseParameterExpression = Expression.Parameter(propertyToUseType, propertyToUse.Substring(0,1));
Expression parentExpression = Expression.Property(workingExpression, propertyToUse);
if (parentExpression.Type.IsGenericType &&
typeof(IEnumerable<>)
.MakeGenericType(parentExpression.Type.GetGenericArguments())
.IsAssignableFrom(parentExpression.Type))
{
Expression childExpression = BuildPropertyExpression(propertyToUseParameterExpression,
workingProperty, comparisonOperation, compareValue);
Type func = typeof(Func<,>);
Type genericFunc = func.MakeGenericType(propertyToUseType, typeof(bool));
LambdaExpression predicate =
Expression.Lambda(genericFunc, childExpression, propertyToUseParameterExpression);
MethodInfo asQueryableMethod = typeof(Queryable).GetMethods()
.Where(m => m.Name == "AsQueryable")
.Single(m => m.IsGenericMethod)
.MakeGenericMethod(propertyToUseType);
Expression asQueryableExpression = Expression.Call(null, asQueryableMethod, parentExpression);
MethodInfo anyMethod = typeof(Queryable).GetMethods()
.Where(m => m.Name == "Any")
.Single(m => m.GetParameters().Length == 2)
.MakeGenericMethod(propertyToUseType);
returnValue = Expression.Call(
null,
anyMethod,
asQueryableExpression,
predicate);
}
There are other factories off the Expression class to help create parts this snip it does not show like
valueExpression = Expression.Constant(compareValue)
and
returnValue = Expression.Equal(workingExpression, valueExpression);
Hope this helps
Buckrogerz
|
|
|
|
|
I did it this way (and I an NOT a JavaScript programmer):
1. JavaScript code:
class JsMath
{
static function Eval(expression: String): double
{
return eval(expression);
};
}
2. Compile:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\jsc.exe /t:library jsMath.js
3. Use in C#:
private static double ExpressionValue(string expr)
{
return JsMath.Eval(expr);
}
|
|
|
|
|
well I suppose that's one way to do it.
Real programmers use butterflies
|
|
|
|
|
Very lazy way
|
|
|
|
|
When deep in the pit of "why won't that button move up just a bit" and googling solution awash with divs, css margins and other cave drawings, I think there must be a way to grab elements from a tool bar and place them where I want then have compiler make it all just work.
I found one in WYSIWYG Web Builder and was able more or less to do what I had envisioned.
So, all you top gun web devs, do you use this stuff or hand roll it still because?
TIA
|
|
|
|
|
No. I use VS (various versions, or occasionally VS Code for PHP development) but NEVER use it in Source / Split view. When I need to tweak / debug CSS I just load the page in Chrome and use dev tools to inspect the applied CSS, add rules, adjust values, and even tinker with the HTML. Then copy/paste changes back to the source. The downside with that is I have to remember all the elements where I changed any CSS values; to make this manageable I tend to work in very small "increments" updating the source CSS / HTML frequently and reloading the page (all very well, of course, unless the page is the result of a complex or non-repeatable transaction).
But then I'm a technophobe; I tend to shun frameworks and a plethora of "tools". My trustiest tool is Notepad (the original version, not ++ or any other enhanced version).
|
|
|
|
|
DerekT-P wrote: Then copy/paste changes back to the source. The downside with that is I have to remember all the elements where I changed any CSS values; to make this manageable I tend to work in very small "increments" updating the source CSS / HTML frequently and reloading the page
You may want to explore the Filesystem tab in Chrome dev tools: it'll save your changes to the original CSS file.
Might just be for when you're working on a localhost webserver, but I've found it pretty useful.
|
|
|
|
|
I use editors first because I hate CSS layout, and a good designer takes care of a lot of the boilerplate though I usually have to go back and modify it by hand. Honestly, I prefer when the design team can produce a mock of the page all laid out and then I templatize and make it dynamic. But then I'm not a web developer and wasn't by trade, though i had to wear a lot of hats at some companies.
Real programmers use butterflies
|
|
|
|
|
Lately I use Visual Studio Code... time ago I used Notepad++.
A lot of years ago I used something similar to Dreamweaver (or how that would have been spelled), but using Chrome, Edge... tools to debug worked very well for me.
Of course I've suffered what is intended to with CSS, but I've done it that way...
PS: I'm not in any way a top gun web dev... I have done some web pages, but always as side jobs or because it was needed to do certain task.
|
|
|
|
|
This is down to how html works. Html elements are placed in a "flow" and the browser "fills" the document space with how those elements flow in. Imagine a glass box that you tipped various amounts of different coloured sand into. Now imagine putting the same sand in a glass box that is wider, or narrower. The red sand might have been an inch from the bottom in the wide box but 2 inches from the bottom in the narrow box.
If you "just want this button up a bit" then you have to take it out of the flow. So if you just want red sand two inches from the bottom then take it out of the sand you flow into the box then stick the red sand to the outside of the box two inches from the bottom. Now no matter the size the box your red sand is always where you want it as it isn't part of the flow. Great....but now resizing the box (your browser) probably doesn't have all the effects you want. Let's say the box is only 1 inch tall and your red sand is "two inches from the bottom"....it's no longer in the view plane.
So it is indeed possible to do what you want by taking elements out of the flow (the css term is absolute positioning) but it results in html that is very easy to break. So instead designers use tricks that ensure the elements look good no matter what container they are flowed into.
|
|
|
|
|
|
F-ES Sitecore wrote: This is down to how html works. Html elements are placed in a "flow"
You know what else flows? Sewage. Strangely enough...
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
I use VS for all web development. I mostly work in the source view especially for layout, otherwise you get a bunch of auto-styles added and lose control your mind.
FWIW, many layout issues can be solved with tables.
"Go forth into the source" - Neal Morse
|
|
|
|
|
Static or dynamic? If static, WYSIWYG (with half a plan) has you up in a day if not hours. Changing doesn't require a brain refresh.
The more popular Hosts have excellent tools.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
What editor did you use?
These days with VS Code + Angular I miss having an editor.
|
|
|
|
|
I used to use HoTMetaL Pro.
Now I just use the editor that came with the hosting stuff.
|
|
|
|