annotate.mononik.com

ASP.NET Web PDF Document Viewer/Editor Control Library

C# 3.0 added query expressions to the language these look superficially similar to SQL queries in some respects, but they do not necessarily involve a database. For example, we could use the data returned by the GetAllFilesInDirectory code from the preceding chapter, reproduced here in Example 8-1. This returns an IEnumera ble<string> containing the filenames of all the files found by recursively searching the

barcode fonts for excel free download, excel barcode generator free download, how to generate barcode in excel 2010, barcode inventory software excel, barcode activex in microsoft office excel 2010, barcode add in for excel free, insert barcode in excel 2016, barcode font for excel 2007 free, excel 2010 barcode font, how to make barcodes in excel 2010,

specified directory. In fact, as we mentioned in the last chapter, it wasn t strictly necessary to work that hard. We implemented the function by hand to illustrate some details of how lazy evaluation works, but as Example 8-1 shows, we can get the .NET Framework class library to do the work for us. The Directory.EnumerateFiles method still enumerates the files in a lazy fashion when used in this recursive search mode it works in much the same way as the example we wrote in the previous chapter.

static IEnumerable<string> GetAllFilesInDirectory(string directoryPath) { return Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories); }

Let s go back to the TextThread and TextDevice classes from the beginning of the chapter. Instead of having the text thread call the text device to pass the text, a signal will be sent. The signal will go from the text thread to the text device receding in the main thread. The new TextThread class can be seen in Listing 12-26. The highlighted lines show the changes that have been made to add a signal and a stop method. In the earlier versions, the class depended on a global flag variable that indicated that the threads should halt execution; in this version, that flag, m_stop, is internal and is set using the stop method. To allow the signal, the Q_OBJECT macro has been added as well as a signals section and an actual signal, writeText, carrying a QString as argument. Listing 12-26. The TextThread with the writeText signal class TextThread : public QThread { Q_OBJECT public: TextThread( const QString& text ); void run(); void stop(); signals: void writeText( const QString& ); private: QString m_text; bool m_stop; }; The TextDevice class has been turned into a thread it now inherits QThread and has the same stop mechanism as the TextThread class. (The class declaration can be seen in Listing 12-27.) The highlighted lines show the Q_OBJECT macro, a public slots section, and the actual slot (write) that accepts a QString as argument. Listing 12-27. The TextDevice class declared as a thread class TextDevice : public QThread { Q_OBJECT

Since a LINQ query can work with any enumeration of objects, we can write a query that just returns the files larger than, say, 10 million bytes, as shown in Example 8-2.

var bigFiles = from file in GetAllFilesInDirectory(@"c:\") where new FileInfo(file).Length > 10000000 select file; foreach (string file in bigFiles) { Console.WriteLine(file); }

As you saw in the previous section, when you register your class, you can specify the base class type from which your class derives. One of the goals of Atlas is to make your JavaScript easier to read and debug, and inheritance is a useful methodology to prevent replication of member variables and methods amongst your classes, helping you achieve this goal. This is probably best demonstrated by example. Earlier you created a Car class for a generic car. Lots of different types of cars exist; for example, a sports utility vehicle (SUV) is different from a sports car in that it will usually have a four-wheel drive (4WD) and the sports car will not. If you want to implement car classes, where you will query the type of 4WD the car has, it makes sense to have a subclass of Car called SUV that has a 4WD property.

As long as the C# file has a using System.Linq; directive at the top (and Visual Studio adds this to new C# files by default) this code will work just fine. Notice that we ve done nothing special to enable the use of a query here the GetAllFilesInDirectory method just returns the lazy enumeration provided by the Directory class. And more generally, this sort of query works with anything that implements IEnumerable<T>. Let s look at the query in more detail. It s common to assign LINQ query expressions into variables declared with the var keyword, as Example 8-2 does:

   Copyright 2020.