|
|
Browse by Tags
All Tags » LINQ (RSS)
-
Over time, I’ve adjusted my code formatting style – changing the white space that I insert, or where I place the parentheses. In this post, I detail some aspects of my current code formatting approach, focusing only on formatting LINQ queries that are written in the ‘method syntax’, not using LINQ query expressions (from --- select ---). Often in the past, I have leaned towards formatting code with an emphasis on reducing line code. I like to see more of my code in a given window, not less. However, Read More...
|
-
LINQ is a great tool for writing ad-hoc queries and transforms, and occasionally I need to write queries or transforms on text files. And sometimes I receive CSV files, and need to do something with them. I wrote a blog post on LINQ to Text files over two years ago. My coding practices today differ from what I presented in that blog post. This post presents my current approach for dealing with text files using LINQ, and includes a function for splitting CSV lines. In that post, I detailed an approach Read More...
|
-
Closures are one of the key components in C# 3.0 that makes functional programming easy, and results in clean syntax. Yet, they are not really necessary to understand in order to write queries in the functional style. Why? Because closures make the language ‘just work’ exactly in the way that you expect. I’ve made use of closures literally hundreds of times in the code that I’ve posted on my blog, yet I’ve never had to call attention to them. This blog post presents a quick and easy explanation of Read More...
|
-
Many types of documents contain code, including API documentation, tutorials, specifications, technical books, and magazine articles. Too often, there is no way to automate testing and validation of this code. This post presents a small example program that shows how to use content controls in Open XML word documents to delineate code snippets so that you can automate validation of the snippets. This scenario was my first use of Open XML – it was the killer application (for me) that prompted me to Read More...
|
-
Today, the development team for the Open XML SDK has announced that they have released the first Community Technology Preview (CTP) of version 2 of the Open XML SDK. Download it at http://go.microsoft.com/fwlink/?LinkId=127912 . There is a lot of very cool stuff in this release, including: Strongly typed document object model (DOM). Tool to compare two Open XML files. Class explorer that helps you understand the markup and determine which classes to use in the strongly typed DOM. Document reflector Read More...
|
-
Content controls are an effective way to add structure to word processing documents. You can write a very small LINQ query to retrieve the contents of content controls. This topic in Office Online provides more information on content controls. In an upcoming post, I’m going to show how you can write a small test harness to test code that is embedded in documents. This is particularly useful, say, to a program manager who has written a specification that contains a lot of code that shows how to use Read More...
|
-
Raw data for a LINQ query doesn’t always come in the form you want. Recently, I had some data like this: string [] source = new [] { "EW" , "Eric" , "8:00" , "DW" , "Dave" , "9:00" , "JA" , "Jim" , "8:00" }; You want to transform the above collection of strings into a collection of anonymous objects that are easier to work on, so you need to write a query that operates on groups of three. To solve this problem, you can take advantage that the Select extension method has an overload that passes an Read More...
|
-
You can use lambda expressions to write an event handler, even for classes that predate C# 3.0 and the latest version of the framework. This can shorten your code, and make it easier to read. For example, the code to validate an XML tree using an XSD schema takes an event handler because it may return multiple errors or warnings for a single validation pass. An easy way to write this code is as follows: using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Xml; Read More...
|
-
Sometimes you need to find the duplicates in a list. I’m currently developing a little utility that tests code in a word processing document (to be blogged soon). Each code snippet in the document has an identifier, and one of the rules that I’m imposing on this code testing utility is that there should be no duplicate identifiers in the set of documents that contain code snippets to be tested. An easy way to find duplicates is to write a query that groups by the identifier, and then filter for groups Read More...
|
-
When developing C# programs in the functional programming style, you often need to dump out a collection to the console. Object dumper is a great tool to use for this. It is a sample that far too few developers know about. A functional transform typically takes the form of successive transformations: transform collection a => collection b => collection c => final collection. This is one of the main points of this topic in my Functional Programming Tutorial . When I commence developing such Read More...
|
-
Just as soon as I learn something, I blog it. This has a potential pitfall – sometimes I blog something and then learn that my approach was incorrect. But I’m not too awfully proud – I just blog again and tell you my new lessons learned. Nearly two years ago, I wrote some LINQ to XML code to use reflection take an object graph composed of anonymous types, and transform it into an XML tree. You can find that blog post here . In my ignorance, I wrote this code in the imperative style. This presents Read More...
|
-
The response to my previous blog post has been very interesting to me. And it has, to a very large extent, matched my own experience. I have seen four basic scenarios where folks use LINQ: Using LINQ to Objects (and LINQ to XML, which is really just LINQ to Objects), primarily using the extension methods, and the so-called ‘method syntax’. This really is a great scenario. When I really understood it, it blew my mind. I believe it leads to the possibility of “speed-reading” code – see below. Using Read More...
|
-
I had an interesting conversation with my nephew the other day. He is a very bright CS student working as a summer intern at a software company (not Microsoft). He is programming in C# using Visual Studio 2008. I asked him if developers at his company were using LINQ, and he said, "No, that the folks in charge had basically forbidden it, because no one understands it." Visual Studio 2008 has been out for over a year, but I know that a fair number of competent developers have not devoted the time Read More...
|
-
This is the eleventh in a series of posts on how to build a LINQ IQueryable provider. If you have not read the previous posts you’ll want to do so before proceeding, or at least before proceeding to copy the code into your own project and telling your boss you single-handedly solved the data layer problem over the weekend....( read more ) Read More...
|
-
In the last three posts, in addition to the information regarding how we want to alter the markup in an Open XML document, I've made a few observations about how to write LINQ to XML code when modifying an XML tree in such a way that it becomes harder to introduce bugs. In addition, I've also mentioned a couple of other points that you can take into consideration - you can write code that performs better if you know a bit about how LINQ to XML operates under the covers. In Using LINQ to XML to Accept Read More...
|
|
|
|