Archive for 'LINQ' Category
LINQ2XMl and namespaces
1 September 2008In Xml namespace are used extensively to distinguish between tag names, you can use namespaces directly with XElement class thanks to the XNamespace class, here is an example.
XNamespace ns = XNamespace.Get("http://www.nablasoft.com/mynamespace");
XElement element = new XElement(ns + "root",
[...]
LINQ, SingleOrDefault and NullObject
20 August 2008Suppose you have this simple class (has no business meaning is valid only as example)
public class MyObject
{
public static MyObject NullValue = new MyObject() { Value = -100, Name = String.Empty };
public Int32 Value { get; set; }
public String Name { get; set; }
[...]
Lambda Lover - argument parser
20 August 2008There are a lot of situations where LINQ and Lambda expressions can make your code simpler to write and also simpler to read. Today I stumble across an extension of a really old project. This project pass one parameter to a function, and this parameter is a list of comma separated BlockName. Despite the business [...]
LINQ and extending it with cross product
13 August 2008Linq to object is really useful in a lot of places around my daily code. This afternoon I have to setup some routine to do crossproduct of some objects. With the term cross product I mean having two set, one made by elements of type X and the other made by elements of type Y, [...]
LINQ ForEach for IEnumerable<T>
13 August 2008It seems to me strange that LINQ does not define an extension method ForEach to apply some Action<T> on an IEnumerable<T>. Array and List both have ForEach() method, and IEnumerable really miss it a lot, but fortunately implementing it is a matter of few lines of code.
public static IEnumerable<T> ForEach<T>(
this [...]
>