Contents tagged with .net
-
Getting a type value from the Request object
A little bit of boiler-plate code I've used in the past for retrieving a value from the asp.net Request object (when working with webform back in the day!) is:
/// <summary>/// Retrieve a value from …
-
A custom model binder for XML content
Most of the time the default model binder in MVC suffices and maps everything into your model cleanly. One thing that you can't do automatically is read XML into an XDocument. You could solve this …
-
Windows Forms marquee style progress bar that doesn't, well, marquee..
If you've got a progress bar where the Style is set to "ProgressBarStyle.Marquee" and the progress bar sits there blank, not scrolling and looking rather sorry for itself, one reason for this is that …
-
The result of a query expression is a query, not the result of the query
This bit me recently. To quote Eric Lippert (last paragraph):
Remember that with LINQ the result of a query expression is a query that can deliver the results when asked, not the results of the …
-
DataTable Key/Value columns to Dictionary
There are undoubtedly more elegant ways to do this using LINQ, but to quickly and easily take the key (int) and value (string) columns from a DataTable and turn them into a Dictionary<int, string>, …
-
A review of "Review: CryptoLicensing for .NET"
The review of CryptoLicensing for .NET that Roy Osherove posted recently was very well written and covered a topic that I've long held a mild level of curiosity around. That topic being protecting …
-
A string of character 'x' the same length as string 'y'
... is quite simple in .net, as I found out! string title = "My line of text that I'm writing to the console underlined with equals signs"; Console.WriteLine(title); …
-
Sorting the results of DirectoryInfo.GetFiles
Say you wanted toget a list of all the SLN (Visual Studio Solution) files in a given directory and all child directories, sorted alphabetically, you could use something similar to this:
public …
-
A number that equals twice the sum of its decimal digits
Riffing on "dix-huit ans aujoud'hui = 18 pounds!" from Frankarr, an australian blogger.
In the entry he mentions that "One fact about 18 which I really love is that 18, aside from 0, is the only …
-
Finding a row in a DataTable
If you have a System.Data.DataTable that contains the columns {ItemId, ItemName, ItemQuantity} and wanted to find the record for a given ItemId, you could always use the followind code:
int …