Archive for the ‘.Net General’ Category

Looping (and modifying) a collection

Ok, back to basics with this one. I have a collection of strings: List<string> someStrings = new List<string>() { “aaaaaaa”, “bbb”, “ccc”, “dddddddd” }; And I want to remove the shorter items (with length < 4), so there should remain two items left. My first (and amateuristic) attempt was this: foreach (string s in someStrings) [...]

DateTime comparisons in .Net

Ok, in software it’s possible to bend time, like in the Matrix. This sounds pretty cool, but it’s only very frustrating! Here’s a simple scenario. I have a timer that elapses every second, and I want to check if it is equal to a specified DateTime variable (which has an accuracy of seconds). The first [...]

Math.Round() and MidPointRounding

Hmmmm. How’s it possible that a method as simple as Math.Round() triggers me to write a post about it? By a coincidence, I stumbled upon the results of these two calls: Math.Round(4.5); //Returns 4 Math.Round(5.5); //Returns 6 I really expected them both to be 5 and 6 (or 4 and 5 for that matters). I [...]

MetadataType attribute

I like the usage of attributes, mostly because it keeps my code clean. At the moment, I'm working with the Entity Framework, so my entities are generated. I want to use attributes for validation, and configure scaffolding (for DynamicData). But how can you place an attribute on a property of a generated class?? If you [...]

Auto increment AssemblyVersion

Ok, in deze post wil ik jullie gewoon een feitje meedelen waar je niet 123 achter komt (ik iig niet) In het huidige software project hebben een update-mechanisme wat checked of er nieuwe updates beschikbaar zijn. Deze check gebeurt aan de hand van de AssemblyFileVersion. Deze info is puur informatief en reflecteert de AssemblyVersion die [...]

Asymmetric Accessor Accessibility

Ik ben een groot voorstander van properties. De logica staat centraal en het maakt de code overzichtelijker. Natuurlijk is het mogelijk om een access modifier (public, private, protected, internal, or protected internal) te specificeren om de toegankelijkheid te bepalen. Maar niet iedereen weet dat het ook mogelijk is om de access te overriden voor een [...]

Datacontract Surrogates

Als je met 3rd party software werkt, en je wilt toch controle hebben over de serialisatie van een bepaald type, gebruik dan DataContract Surrogates.  Stel, je wilt een extern type serialiseren die je niet zomaar kan wijzigen. Dan kan je een eigen kopie van die class maken, en hier de gewenste attributen definieren. Vervolgens moet [...]