Browse by Tags
All Tags »
LINQ (
RSS)
Sometime ago I wrote a predicate equality comparer to be used with LINQ ’s Distinct operator. The Distinct operator uses an instance of an internal Set class to maintain the collection of distinct elements in the source collection which in turn checks...
In a previous post I showed how to create expression trees to set properties on an object. The way I did it was not very developer friendly. It involved explicitly creating the necessary expressions because the compiler won’t generate expression trees...
Following my last posts ( > )( > ), in this post I’ll introduce the implementation of the SkipLastWhile operator. The SkipLastWhile returns all but the last contiguous elements from a a sequence that satisfy the specified criteria and is implemented...
Following my last post , in this post I’ll introduce the implementation of the SkipLast operator. The SkipLast operator returns all but a specified number of contiguous elements from the end of a sequence and is implemented as the SkipLast extension method...
After having introduced the TakeLast operators ( > )( > )( > ), it makes sense to introduce their duals: the SkipLast operators. Name Description Example SkipLast<TSource>(IEnumerable<TSource>) Returns all but a specified number of...
Following my last posts ( > )( > ), in this post I’ll introduce the implementation of the TakeLastWhile operator. The TakeLastWhile operator returns last contiguous elements from a sequence that satisfy the specified criteria and is implemented...
Following my last post , in this post I’ll introduce the implementation of the TakeLast operator. The TakeLast operator returns a specified number of contiguous elements from the end of a sequence and is implemented as the TakeLast extension method :...
Some time ago I needed to retrieve the last items of a sequence that satisfied some criteria and, looking at the operators available in the Enumerable class, I noticed that there wasn’t such operator. The only way to achieve this was to reverse the sequence...
I’ve created a project on CodePlex to share my LINQ utilities and operators: PauloMorgado.Linq In this project you can find the code from my previous posts about the Distinct operator: LINQ: Enhancing Distinct With The PredicateEqualityComparer LINQ:...
To finalize this series on object hydration, I’ll show some performance comparisons between the different methods of hydrating objects. For the purpose of this exercise, I’ll use this class: class SomeType { public int Id { get ; set ; } public string...
In my previous post I showed how to hydrate objects by creating instances and setting properties in those instances. But, if the intent is to hydrate the objects from data, why not having an expression that does just that? That’s what the member initialization...
After my post about dumping objects using expression trees , I’ve been asked if the same could be done for hydrating objects. Sure it can, but it might not be that easy. What we are looking for is a way to set properties on objects of an unknown type...
Following my last post , I received lots of enquiries about how got to master the creation of expression trees . The answer is: .NET Reflector On that post I needed to to generate an expression tree for this expression: Expression < Func < object...
No. I’m not proposing to get rid of objects. A colleague of mine was asked if I knew a way to dump a list of objects of unknown type into a DataTable with better performance than the way he was using. The objects being dumped usually have over a...
On my last post , I introduced the PredicateEqualityComparer and a Distinct extension method that receives a predicate to internally create a PredicateEqualityComparer to filter elements. Using the predicate, greatly improves readability, conciseness...
Today I was writing a LINQ query and I needed to select distinct values based on a comparison criteria. Fortunately, LINQ’ s Distinct method allows an equality comparer to be supplied, but, unfortunately, sometimes, this means having to write custom equality...
Like other LINQ API methods that extract a scalar value from a sequence, Single has a companion SingleOrDefault . The documentation of SingleOrDefault states that it returns a single, specific element of a sequence of values, or a default value if no...
I’ve witnessed and been involved in several discussions around the correctness or usefulness of the Single method in the LINQ API. The most common argument is that you are querying for the first element on the result set and an exception will be thrown...
Today, my friend Nuno was writing some code to get the PropertyInfo s of a class implementation of an interface. Given this interface: public interface ISomeInterface { int IntProperty { get ; set ; } string StringProperty { get ; } void Method(); } and...
Visual Studio uses Publicize to create accessors public for private members and types of a type. But when you try to set elements of a private array of elements of a private type, things get complicated. Imagine this hypothetic class to test: public static...
Filed under: .NET, C#, Microsoft, MSDN, VisualStudio, Testing, LINQ, VisualStudio2008, VisualStudio2010, TipsAndTricks, .NET2.0, .NET3.5, .NET4.0
More Posts
Next page »