Site: http://weblogs.asp.net/fmarguerie/default.aspx Link: http://weblogs.asp.net/fmarguerie/rss.aspx
by Fabrice Marguerie via Fabrice's weblog on 11/20/2009 11:07:00 AM
When I finalized my article about memory leaks, I removed a part about Infragistics NetAdvantage. Here it is. It may be useful to some of you. Warning: It's based on NetAdvantage 7.3, and may or may not apply to recent versions. Let's take an example. In project X, visual controls from the Infragistics NetAdvantage suite are used to build the GUI. One of these controls is the UltraToolbar. As told by its name, this control is used to display toolbars. The way a UltraToolbar is used is via a Ult ...
[ read more ]
by Fabrice Marguerie via Fabrice's weblog on 5/21/2009 10:04:00 AM
Eric Lippert, whose blog you shouldn't miss, adds his own arguments to the debate about whether using a ForEach extension method instead of foreach is a good idea or a bad one.I don't see a definitive answer to the question. All the arguments given here and elsewhere are good, but in the end, it's up to you to decide what you prefer to do.Read the posts and the comments to make up your own mind. Cross-posted from http://linqinaction.net ...
by Fabrice Marguerie via Fabrice's weblog on 2/25/2009 6:20:00 PM
In LINQ in Action, we discuss about the missing ForEach query operator. This is in Chapter 5 "Beyond basic in-memory queries", more precisely in section 5.2.2. There, we indicate that Eric White suggested this operator in his functional programming tutorial, although I'm not able to find the exact reference at the moment in this tutorial. Since then, a lot of people have been asking for ForEach. This can be seen on Kirill Osenkov's blog, where you'll find links to discussions about whether ForEa ...
by Fabrice Marguerie via Fabrice's weblog on 2/12/2009 10:58:00 AM
This is just a quick post to make a plug for the Null Object design pattern. I don't think that it's used a lot, but it's useful to avoid a lot of issues. It's very common to create or use methods and properties that return null. That's not surprising. It's part of most of the programming languages we use nowadays. However, returning null can lead to issues because if the callers forget to test for null, it will likely provoke a NullReferenceException (or equivalent). What the Null Object des ...
by Fabrice Marguerie via Fabrice's weblog on 2/6/2009 5:11:00 PM
Yesterday a reader of the LINQ in Action book posted an interesting challenge on the book's forum. It's interesting enough to be reposted it here. The request was to convert a LINQ query expression (query syntax) to a query operator call chain (method syntax or dot notation). The original query was the following one: from publisher in SampleData.Publishers join book in SampleData.Books on publisher equals book.Publisher into publisherBooks from book in publisherBooks.DefaultIfEmpty() ...
by Fabrice Marguerie via Fabrice's weblog on 11/10/2008 10:40:00 PM
Yesterday, Fred asked me if I could help him to convert C# code to LINQ. The solution may not obvious to find unless you know LINQ well. I will reproduce here the solution I gave Fred. Whether the LINQ version of the code is easier to read than the original one is arguable. The purpose here is more to show LINQ's Select query operator in action. Here is the original code: int CountCorrectChars(string proposedValue, string correctValue){ int correctCount = 0; for (int i=0; i < pr ...
by Fabrice Marguerie via Fabrice's weblog on 4/24/2008 1:52:00 PM
I'm not that much a fan of fluent interfaces, but in some cases they are well fit.A great example is the fluent repeater created by Adrian Aisemberg. It's also a good example if you don't know what a fluent interface is.Here is sample code that uses it:Repeat.Call<string>(Save).WithParameters("myfile.txt").UntilSucceeds.Start(10);Repeat.Call(Ping).PauseBetweenCalls(2000).Start(100);Some more:Repeat.Call(Open).InBackgroundThread.At(ThreadPriority.Lowest). ...
by Fabrice Marguerie via Fabrice's weblog on 1/2/2008 12:14:00 PM
Did you know that depending on the way you rethrow exceptions you may lose important information? There are already several blog posts that explain and demonstrate the difference between throw and throw ex. I'm realizing only now that none of the two solutions yields the complete call stack trace information!Let's see what the problem is and I'll show you the real solution.I'll use the following method to generate an exception:private static void BadWork(){ int i = 0; int j = 12 / i; ...
by Fabrice Marguerie via Fabrice's weblog on 12/22/2007 11:37:00 PM
If for some reason you need to convert an ISBN-13 to ISBN-10 (one being that Amazon doesn't support ISBN-13 in product affiliate links) then you need not only to remove the first three characters. You also need to recompute the checksum. Here is a piece of code that I wrote to handle this conversion: public static String Isbn13to10(String isbn13){ if (String.IsNullOrEmpty(isbn13)) throw new ArgumentNullException("isbn13"); isbn13 = isbn13.Replace("-", "").Replace(" ...
by Fabrice Marguerie via Fabrice's weblog on 12/5/2007 5:04:00 PM
Often, when you try to find out how to write the correct LINQ query you need, you end up being confused because it becomes too complex. In such situations, you should remember that the let clause is here to help you. Let's see is an example from the official LINQ forum.Someone asked how to query the following XML document: <cars> <car name="Toyota Coupe"> <profile name="Vendor" value="Toyota"/> <profile name="Model" value="Celica"/&g ...
by Fabrice Marguerie via Fabrice's weblog on 9/15/2007 5:57:00 PM
We will soon publish excerpts of the LINQ in Action book. One of them will probably show you how to query non-generic collections. Before it becomes available, let me show you an overview of what it presents. When you read and hear about LINQ, you almost always see queries that work on the generic collections provided by the .NET Framework. In fact, you can use LINQ to Objects with any type that implements IEnumerable<T>. This means that LINQ to Objects will work with your own generic col ...
by Fabrice Marguerie via Fabrice's weblog on 7/17/2007 9:55:00 PM
When debugging LINQ to SQL code, did you wish you could easily see the SQL that gets executed? Of course there is the DataContext.Log property that is available for that. You can assign any TextWriter to this property. Console.Out is a good candidate for example, but it doesn't help much for web applications and doesn't integrate with Visual Studio nicely. Fortunately, Kris Vandermotten has a nice solution: DebuggerWriter. It's an implementation of TextWriter that writes to the debugger log.With ...
by fmarguerie via Fabrice's weblog on 4/21/2007 6:44:00 PM
LINQ to Objects is a great improvement in .NET 3.5 to query in-memory collections. It offers a nice declarative query syntax, strong-typing and support for a rich set of operations. One of the things that LINQ to Objects does not offer is indexing. Indexing collections of objects could greatly improve the performance of queries. Some people realized this and Aaron Erickson even extended LINQ to Objects to provide support for indexing. i4o (indexes for objects) is the solution he proposes. i4o is ...
by fmarguerie via Fabrice's weblog on 4/9/2007 9:18:00 PM
In the spirit of LINQ to Amazon now comes LINQ to Flickr. Mohammed Hossam El-Din (Bashmohandes) proposes an implementation that is very close to what I created with LINQ to Amazon, except that this time it's the Flickr API that is used thanks to the FlickrNet library. I'm quite sure we will soon see more LINQ flavors appear to query various data sources. There is already work started to create LINQ to NHibernate and LINQ to LDAP APIs, for example. Cross-posted from http://linqinaction. ...
by fmarguerie via Fabrice's weblog on 3/28/2007 9:16:00 PM
Do you want to see LINQ used for something else than querying a database for customers or for querying an array of dummy strings? After Derek Slager who showed us how he calculates baseball statistics with LINQ, here is another different use of LINQ. Luke Hoban, Program Manager for the C# Compiler, shows how LINQ can be used to solve puzzles. The diagram below provided by Luke shows a mobile. It consists in a bunch of weights (A-M) hanging from a system of bars. Each weight has an integer value ...
by fmarguerie via Fabrice's weblog on 1/16/2007 10:31:00 PM
Paul Sheriff has just published an example he uses to recommend the use of try..finally blocks. Here is his example: private void CreateLogFile() { try { StreamWriter sw = new StreamWriter(@"D:\Samples\Test.txt", true, System.Text.UTF8Encoding.UTF8); sw.WriteLine("This is some text"); sw.Close(); } catch(Exception ex) { &nb ...
by fmarguerie via Fabrice's weblog on 1/8/2007 10:12:00 AM
Steve has published on his blog a sample from the book we are working on together. This example shows how LINQ to XML makes it easy to convert a CSV file into an XML document. Going from CSV to XML doesn't require something more complicated than this: XElement xml = new XElement("books", from line in File.ReadAllLines("books.txt") where !line.StartsWith("#") let items = line.Split(',') &n ...
by fmarguerie via Fabrice's weblog on 12/28/2006 11:41:00 AM
Nikhil Kothari, whose blog you should visit immediately if you're doing web development, demonstrates how to reproduce LINQ to Objects in JavaScript.Nikhil is an architect on the Web Platform and Tools team at Microsoft known for his great projects, past and present, which include: ASP.NET Web Matrix, Web Development Helper, and Script#.This time, Nikhil has a post in which he demonstrates how it's possible to write queries against JavaScript arrays, similarly to what LINQ to Objects of ...
by fmarguerie via Fabrice's weblog on 12/15/2006 12:42:00 PM
I've just downloaded Visual Studio 2006 err.. Visual Studio 2005's first service pack. Well, it's a 431MB download... Not bad for a patch. Several issues have been fixed, of course, but new features also have been integrated such as the support for Web Application projects. The service pack is available in multiple editions, depending on the version of Visual Studio 2005 you are using: Visual Studio 2005 Team Suite SP1 (includes SP1 updates for Standard, Professional, and Te ...
by fmarguerie via Fabrice's weblog on 10/31/2006 4:50:00 AM
It's often useful to remove diacritic marks (often called accent marks) from characters. You know: tilde, cédille, umlaut and friends. This means 'é' becomes 'e', 'ü' becomes 'u' or 'à' becomes 'a'. This could be used for indexing or to build simple URLs, for example. Doing so is not so easy if you don't know the trick. You can play with String.Replace or regular expressions... But do you know .NET 2 has all that i ...
by fmarguerie via Fabrice's weblog on 9/29/2006 6:16:00 PM
The first CTP of Visual Studio "Orcas" is available for download. The good news: it's available as a virtual machine!Partial Linq support is in there, but nothing close to what we get with the May CTP of Linq.Here are some of the included features:LINQ to Objects API (in the new System.Core assembly)Partial C# 3.0 support (local variable type interface, lambda expressions, object initializers)Partial C# 3.0 IDE supportPartial VB 9.0 support (local variable type inference, Option In ...
by fmarguerie via Fabrice's weblog on 8/8/2006 4:31:00 AM
I've been extensively using the CAB (Composite UI Application Block) and the SCSF (Smart Client Software Factory) lately. You should really dig them if you are creating Windows Forms applications. The CAB is a great tool to structure your developments and create reusable components. The SCSF is great for working with the CAB...Eugenio Pace, product manager at Microsoft Patterns & Practices, has compiled a list of resources about the CAB and the SCSF. This can be really useful if you are ...
by fmarguerie via Fabrice's weblog on 8/3/2006 3:44:00 AM
Eric White, Programming Writer for XLinq, MSXML, and XmlLite, shows how he used Linq to XML (XLinq) to query Word documents.This is good example to get an idea of where Linq will help us. Linq comes with a set of features that greatly simplify the code needed to manipulate XML documents, either for querying them or for creating them.Eric's post comes with the complete source code. I suggest you take a look at it so you can quickly make your own idea on Linq to XML.You may also read this post ...
by fmarguerie via Fabrice's weblog on 7/28/2006 8:51:00 PM
In the official Linq forum, Joe Albahari presents the reasons why he thinks Linq will succeed:LINQ syntax beats SQL syntax. SQL is flawed in that queries become exponentially difficult to write as their complexity grows. LINQ scales much better in this regard. Once you get used to it, it's hard to go back.Database queries are easily composable. You can conditionally add an ORDER BY or WHERE predicate without discovering at run-time that a certain string combination generates a syntax error.M ...
by fmarguerie via Fabrice's weblog on 7/23/2006 3:21:00 AM
I've just noticed that the Visual Studio "Servicing" web page has been updated with new release dates for the Visual Studio 2003 and 2005 service packs:Visual Studio 2003 Service Pack 1 to ship August 15, 2006Visual Studio 2005 Service Pack 1 ships Q3, 2006 Keep in mind that these dates already slipped before... ...
by fmarguerie via Fabrice's weblog on 7/20/2006 4:21:00 AM
Microsoft listened to our requests. It has announced its upcoming tool for generating MSDN-like documentation from your .NET code. The codename is Sandcastle and the tool is presented as a "Documentation Compiler". It should work the same way NDoc does, except it will support .NET 2. The first release has been delayed and is now planned for August, as part of the next CTP release of the Visual Studio SDK.The information comes from Microsoft's forums. Update: an alpha version is now ...
by fmarguerie via Fabrice's weblog on 7/7/2006 2:07:00 AM
If you want to learn more about Linq, Bill Wagner has a great series over at his blog. Here is a link to the latest post, which includes links to all the other parts. Enjoy! Cross-posted from http://linqinaction.net ...
by fmarguerie via Fabrice's weblog on 7/6/2006 9:25:00 PM
As a followup to my last post, you can read Daniel Cazzulino's post in which he presents a solution for strongly-typed reflection that complements ayende's approach. Of course this implementation has limitations of its own, the major one being that it's based on lambda expressions and expression trees, two features that won't see the light of day before the next version of C# (sometime in 2007?). Share this post: Email it! | bookmark it! | digg it! | reddit! ...
by fmarguerie via Fabrice's weblog on 7/5/2006 4:06:00 PM
.NET reflection features are powerful and this is really what makes it a powerful platform. We don't use reflection everyday, but when we do it's really useful.Don't you hate it though when you have to write code like this?:MethodInfo method = typeof(MyClass).GetMethod("MyMethod");The problem with this code is that we use a string to identify the method, which means that we don't get compile-time validation.Ayende has an interesting approach to this problem. He gives you a solution that allows w ...
by fmarguerie via Fabrice's weblog on 6/30/2006 6:20:00 PM
How many tools do you think we can use for .NET development?Well, more than 905 tools (including 292 libraries) according to what I have referenced in SharpToolbox so far! How many do you actually know? ;-)I started collecting this information more than three years ago now... It's been a while since I've taken a look at the counters.If I remember well, the latest categories that I've added are Grid computing, Workflow, Rich-client UI. The categories with the most tools are IDE - IDE-addins, Pers ...
by fmarguerie via Fabrice's weblog on 6/29/2006 3:39:00 AM
On Monday, I have announced an implementation of Linq for Amazon Web Services, that allows to query for books using the following syntax:var query = from book in new Amazon.BookSearch() where book.Title.Contains("ajax") && (book.Publisher == "Manning") && (book.Price <= 25) && (book.Condition == BookCondition.New) select book;Before getting to the details of the implementation co ...
by fmarguerie via Fabrice's weblog on 6/26/2006 7:33:00 PM
As an example that will be included in the Linq in Action book, I've created an example that shows how Linq can be extended to query anything.This example introduces Linq to Amazon, which allows querying Amazon for books using Linq! It uses Linq's extensibility to allow for language-integrated queries against a book catalog. The Linq query gets converted to REST URLs supported by Amazon's web services. These services return XML. The results are converted from XML to .NET objects using Linq to XM ...
by fmarguerie via Fabrice's weblog on 6/22/2006 5:47:00 AM
Soma announced that the naming scheme for the Linq technologies has been simplified:LINQ to ADO.NET includes: LINQ to DataSet LINQ to Entities LINQ to SQL (formerly DLinq)LINQ support for other data types includes: LINQ to XML (formerly XLinq) LINQ to ObjectsSo long DLinq and XLinq... Welcome Linq to Whatever!I agree that this will make thing ...
by fmarguerie via Fabrice's weblog on 6/17/2006 5:52:00 AM
The original articles about the ADO.NET Entity Framework didn't stay online very long, but this time, two official documents are available:The ADO.NET Entity Framework OverviewNext-Generation Data Access (Making the conceptual level real)These documents will give you an overview of what is coming in the next version of ADO.NET, mainly the ADO.NET Entity Framework, which is Microsoft's upcoming solution for mapping data to objects.In these documents, you'll encounter the following:The Entity Data ...
by fmarguerie via Fabrice's weblog on 6/13/2006 5:18:00 AM
Some of you may have read the documents on ADO.NET 3.0 and the Entity Framework when they were published, before they were promptly removed. The big question since that time has been: What will happen to DLinq in regard to the future of ADO.NET, which seemed to offer the same services and more with a different solution? Well, Andres Aguiar has the scoop, live from TechEd in Boston: apparently both frameworks will be kept. OK, it actually happened. We'll have two mapping technologies in .NET v.ne ...
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.