Saturday, December 30, 2017

Be careful when using many HttpClient instances

Who knew? According to MSDN (emphasis added):
HttpClient is intended to be instantiated once and re-used throughout the life of an application. Instantiating an HttpClient class for every request will exhaust the number of sockets available under heavy loads.
See more here: Disposable, Finalizers, and HttpClient

Wednesday, December 13, 2017

Cool JSON and SQL-related links found on a Hacker News post

https://quicktype.io/ – Parses sample JSON and creates code to serialize/deserialize it in several different languages.

https://github.com/rspeele/Rezoom.SQL – Rezoom.SQL is an F# ORM for SQL databases using type providers, so it will automatically pick up the schema on build. A HN commenter claimed it has better type support than any other ORM, a statement perhaps to be taken with a grain of salt.

https://github.com/ReactiveX/IxJS – Interactive Extensions for JavaScript (IxJS). IxJS is a set of libraries to compose synchronous and asynchronous collections and Array#extras style composition in JavaScript

Wednesday, November 22, 2017

Git line endings revisited and .gitignore

Git-scm.com revised their line ending fix-up instructions in a way that seems to remove ignored files from the repository.

Here are the new instructions:

echo "* text=auto" >.gitattributes
git read-tree --empty   # Clean index, force re-scan of working directory
git add .
git status              # Show files that will be normalized
git commit -m "Introduce end-of-line normalization"

Wednesday, September 20, 2017

.NET IsAssignableFrom

For some reason I have a mental block remembering which way .NET's IsAssignableFrom() function works, so, using the excellent LINQPad and the following code snippet, I came up with the following results:
typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass)) // true
typeof(DerivedClass).IsAssignableFrom(typeof(BaseClass)) // false
Code:
void Main()
{
 typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass)).Dump("typeof(BaseClass).IsAssignableFrom(typeof(DerivedClass))");
 typeof(DerivedClass).IsAssignableFrom(typeof(BaseClass)).Dump("typeof(DerivedClass).IsAssignableFrom(typeof(BaseClass))");
}
    
class BaseClass { }
class DerivedClass : BaseClass { }

Thursday, June 08, 2017

C# 6 String Interpolation Does Not Concatenate

Well, I learned something new today that's slightly disappointing. I had thought that C# 6 string interpolation concatenated strings or perhaps used the StringBuilder or some such under the hood. It turns out it merely creates a good, old-fashioned String.Format statement out of it.

Given this source code:

The resulting IL (compiled) code is the following (obtained using LINQPad):

Note the following two statements:
ldstr       "A{0}C"
call        System.String.Format
These indicate that String.Format is being called with the familiar-looking format string "A{0}C".


To compile the C# code and create IL code, I used Joe Albahari's excellent LINQPad program.

Wednesday, March 29, 2017

WebClient vs HttpClient vs HttpWebRequest

All the clients explained.

http://www.diogonunes.com/blog/webclient-vs-httpclient-vs-httpwebrequest/

To quote from the link:
  • HttpWebRequest for control
  • WebClient for simplicity and brevity
  • RestSharp for both on non-.NET 4.5 environments
  • HttpClient for both + async features on .NET 4.5 environments