Search
Code Better
-
Recent Posts
Categories
Category Archives: Topic
Deserializing to Dynamic with RestSharp
You can use JSON.NET to convert any RestSharp service response to a list of dynamic instances; you just need a bit of plumbing code to do it. Continue reading
Writing Automated Performance Tests
I found a memory leak in my application, and wrote an automated test using GC.GetTotalMemory to tell if objects were leaking or not. They were (20MB of them in 100k instances). Continue reading
Posted in Core .NET, Silverlight, Wndows Forms, WPF
Tagged automated testing, memory leaks
Leave a comment
DriveInfo: Total vs. Available Free Space
DriveInfo.AvailableFreeSpace gives you free space with quotas applied; on the other hand, TotalFreeSpace gives you the total, physical amount of empty space on the drive. Continue reading
Drawing vs. Updating and IsFixedTimeStamp (XNA)
XNA.Game.IsFixedTimeStep allows you to run Draw calls after every update, or to limit them to a certain FPS (and also provide fixed-time updates instead of variable ones). Continue reading
Running Windows Services in Visual Studio
You can run a project that’s a Windows service with an infinite loop (yes, really) by invoking the service and waiting. Forever. You can do this conditionally (while not debugging), instead of running ServiceBase.Run. Continue reading
Using Enumerations as Bit Flags
You can use enumerations as bit flags. The FlagsAttribute is optional; more importantly, you need to assign powers of 2^n to the enum’s values. Depending on the .NET version, checking can be easy (.HasFlag) or hard (bitwise AND operation) Continue reading
Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF
Tagged bitwise operators, enumerations
Leave a comment
Creating an Instance Without Using Constructors
You can create an instance of a class without calling any of its contructors, via a call to System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(A)). Scary, but useful in certain cases (like creating instances of highly-coupled or hard-to-instantiate classes in tests). Continue reading
Simple Strategies to Boost SQL Server Performance
SQL Server can be a beast on your disk. Two easy ways to help raise performance for high-volume databases: Use a drive other than the Windows partition for the SQL Server DB files, and split the MDF and LDF files onto different drives if possible. Continue reading
Storing a String List in App.Config or Web.Config
How can you store a list of strings (or ints, say) into a single appSetting key/value pair? Surprisingly, it’s as easy as using a delimited list (like comma-delimited or semicolon-delimited) and splitting it at runtime. Continue reading
Posted in Core .NET, Silverlight, Web, Wndows Forms, WPF
Tagged app.config, web.config
Leave a comment
Procedure Expects Parameter Which Was Not Supplied
SqlCommand’s Parameters prevent SQL injection attacks. Surprisingly, when passed in a null value, you get the exception: Procedure or function “…” expects parameter ‘@foo’, which was not supplied. Continue reading