If you are a heavy LINQPad user you have probably wished to be able to see query execution plan details inside LINQPad. Currently the only way to view query execution plan is to switch to SQL tab, click Analyze SQL button and open the query in SQL Server Management Studio. I got tired of clicking all these buttons and decided to write custom visualizer which solves the issue. With LINQPad.QueryPlanVisualizer you can now view query execution plan and missing indexes as well as create those missing indexes without leaving LINQPad. Continue Reading →
Some time ago I came across a post where the author wanted to turn on and off num lock, cap lock and scroll lock led light without actually toggling their state. This sounded challenging and impossible but after some googling I found a piece of code in C for achieving exactly what I was looking for. In this post I show how it works and how to port it to C# Continue Reading →
This post is part of a series about building a simple mathematical expression evaluator. For previous posts and full source code see Table of Contents.
In previous part we added support for variables but it has a big disadvantage: values of the variables are bound by position and not by name. This means that you should pass values for the variables in the same order as they appear in the expression. For example the following test will fail: Continue Reading →
You have probably heard about Reactive Extensions, a library from Microsoft that greatly simplifies working with asynchronous data streams and allows to query them with Linq operators. There are many different scenarios where using rx results in a much more simple and flexible code. This post demonstrates how to use reactive extensions for loading data from database asynchronously in chunks. Continue Reading →
In part two of this series we built an expression evaluator capable of parsing expressions with parentheses. In this part we are going to add support for expression with variables.
In previous post I showed how to build a simple expression evaluator using expression trees. Although it works fine it has some drawbacks:
- It does not support parentheses.
- It does not support variables.
- In some cases the result can be wrong as the parser is not using left to right parsing.
- It is compiling delegates for every expression which results in slower execution.
To solve these issues we will use a different algorithm and deal with all points except variable support.
This is first part of a series about writing expression evaluator in C#. Even though there are several of them available already I decided to write my own as this one is based on expression trees and is very simple. The evaluator supports numeric expressions as well as expression with parameters. Continue Reading →
This is table of contents for Building Expression Evaluator with Expression Trees in C# series. We are going to build a simple mathematical expression evaluator in C# using expression trees. The library supports simple expressions such as
5/2/2+1.5*3+4.58, expressions with parentheses
(((9-6/2)*2-4)/2-6-1)/(2+24/(2+4)) and expressions with variables:
var a = 6; var b = 4.32m; var c = 24.15m; Assert.That(engine.Evaluate("(((9-a/2)*2-b)/2-a-1)/(2+c/(2+4))", a, b, c), Is.EqualTo((((9 - a / 2) * 2 - b) / 2 - a - 1) / (2 + c / (2 + 4))));
At the end of the series full source code
will be available at github and the library will be published to NuGet.
Source code is available at github: Math-Expression-Evaluator
Table of Contents
- Building Expression Evaluator with Expression Trees in C# – A basic implementation.
- Building Expression Evaluator with Expression Trees in C# – Adding support for parentheses.
- Building Expression Evaluator with Expression Trees in C# – Adding support for variables.
- Building Expression Evaluator with Expression Trees in C# – Improving the Api
In previous post I showed an approach combining DynamicObject with ViewState for accessing ViewState members using dynamic properties instead of string indexes. However that approach had some disadvantages:
- It is tied some a concrete base page class.
- It does not have all the properties/methods of StateBag class
- Mixing ViewState and ViewBag can be confusing for new developers.
If you have worked with ASP.Net MVC 3 you are probably aware of ViewBag property which allows you to pass data from Controller to View by using dynamic properties instead of hard coding strings. While the properties still are not strongly typed and compiler does not check them it can provide an advantage. For example you can avoid casting as it returns dynamic objects. This post will show how to use the same approach in ASP.Net Web Forms for ViewState property giving us a dynamic viewstate class. Continue Reading →