Last night I was dealing with anonymous types and some IL code to creating and assigning values to instances of anonymous types. I stumbled upon this question: How do I declare a Field with Anonymous Type (C#) – http://stackoverflow.com/questions/964334/how-do-i-declare-a-field-with-anonymous-type-c It didn’t have anything to do with what I was doing but the thing I was … Continue reading »
Tagged with c# …
C#, Why params object[] should be forbidden! (v2)
Edit: This post has been rewritten since I first wrote it. I wrote the first edition in frustration and wasn’t to clear on my point. Lets start with a sample. First we have a method accepting an int[], using the params keyword. It just tries to output them. Lets consume it Fine. Just what we … Continue reading »
C#, Parallel deserialization of JSON stored in database
The scenario A while back ago I had to yield entities constructed by deserializing JSON stored in a database. The first solution just opened a simple single result, sequential reader against the database returning a one column result set containing JSON. This was just yield returned after deserialized to the desired entity. Trying to tweak … Continue reading »
C#, Visual Studio 2010, No more Client profile in 5minutes.
I guess I’m not alone being tired of running into the “Client profile” framework version used when creating a Console application in Visual Studio 2010. Don’t know how life is going to be in coming version of Visual Studio, but until then, lets show you a solution that takes no more than 5 minutes. Step … Continue reading »
C#, Generic factory with support for private constructors
Today I got involved in a small question on Twitter on how to create a generic factory creating instances of classes having a private constructor. So I put together a small sample that shows a two solutions: Using Activator (around 22s per 100000) Using compiled lambdas (around 8s per 100000) The example lets you time … Continue reading »
Ensure.That – a simple guard clause project
Yes I know there’s a bunch of these projects out there already and that there’s built in support for using code-contracts in .Net, but even so we found a need for a custom API, hence Ensure.That was created. Also, I think Microsoft’s Code-contracts fails on the part of having to install an add-on to VS2010 … Continue reading »
C# – Building a dynamic method recorder using DynamicObject
Was at an OpenSpace event today in Stockholm. Was really great. Lots of inspiring discussions. Was in a discussion about Ruby/IronRuby and C# where there was this case where a methodcall recorder was built with a few lines in Ruby and that it wasn’t doable that easy in C#. Well, I kind of disagree and … Continue reading »
C#, Clean up your Linq-queries and lambda expressions for Non Linq to objects
This is an update to my post “C#, Clean up your Linq-queries and lambda expressions”, where I got a comment that it will not work other than against Linq to objects. That is somewhat true. It will work but the query will fetch all posts from the database and then apply the where clause to … Continue reading »
C#, Clean up your Linq-queries and lambda expressions
Part 2 – How to get it to work against non Linq to object sources Last week something caught my eyes. How scattered business logic can become if you let your binary expressions be used “here and there” when matching entities against certain rules. Logic for a single entity, e.g Customer can be used all … Continue reading »
C# – Custom datareader for SqlBulkCopy
When prototyping SisoDb I used datatables under the covers when consuming the SqlBulkCopy class to insert data. This lead to that I had the source entities in memory as well as the datatables. Since the SqlBulkCopy class can work with readers I created a very simple datareader implementation over my entities instead. I gained a … Continue reading »