<<

US 20090234804A1 (19) United States (12) Patent Application Publication (10) Pub. No.: US 2009/0234804 A1 Whitechapel et al. (43) Pub. Date: Sep. 17, 2009

(54) USING EXTENSION METHODS TO EXTEND Publication Classification COMOBJECTS (51) Int. Cl. G06F 9/54 (2006.01) (75) Inventors: David Andrew Whitechapel, G06F 7/10 (2006.01) Seattle, WA (US); Vladimir G06F 7/30 (2006.01) Morozov, Sammamish, WA (US); (52) U.S. Cl...... 707/3; 719/328; 707/E17.014 Phillip Michael Hoff, Duvall, WA (57) ABSTRACT (US) When objects are called by a program written in a strongly typed language using an interface written in a loosely-typed Correspondence Address: manner, incompatibilities between the programming lan MCROSOFT CORPORATION guages can cause problems. Extension methods can simplify the interface between objects in an object model and a pro ONE MCROSOFT WAY gram written in a strongly-typed programming language by REDMOND, WA 98052 (US) providing method overloads that accept strongly-typed parameters. Extension methods are provided that use method overloads that accept strongly-typed parameters, improving (73) Assignee: Microsoft Corporation, Redmond, type safety by allowing the to enforce type safety WA (US) rather than relying on type checking at runtime. Nullable types and object initialization may be used to provide (21) Appl. No.: 12/046,446 strongly-typed optional parameters. Extension methods can be used to support parameterized properties and to Support class indexers, enabling query of collections of in-memory (22) Filed: Mar. 12, 2008 objects.

USER INTERFACE 640

NATIVE CODE 611 SOURCE CODE EDITOR 651 L COMPLER SOURCE 660 CODE COMPONENT 610 INTERMEDIATE METADATA LANGUAGE 640 SOURCE COMPONENT 650 COMPLER 620

COMMON LANGUAGE RUNTIME IDE 600 ENVIRONMENT 602 Patent Application Publication Sep. 17, 2009 Sheet 1 of 4 US 2009/0234804 A1

Object 1 145 Library of Programming extension Library of language methods shared package 135 115 objects 165 program 125

FIG. 1 Patent Application Publication Sep. 17, 2009 Sheet 2 of 4 US 2009/0234804 A1

Program calls extension method 302

Library of extension method is accessed 304

Extension method fills in missing parameters, etc. 306

Function is performed 308

FIG. 2 Patent Application Publication Sep. 17, 2009 Sheet 3 of 4 US 2009/0234804 A1

Operating System 528

Processi ng Unit 514 Output Output Adapter(s) 542 Device(s) 540

| System Interface H. Input Device(s) Memory 516 Ports(s) 538 536 Volatile 520 Non Volatile 522

1- System Bus 518

Interface 526 Communication Network Connection(s) Interface 548 550

Disk Storage 524

Memory Storage

Computer 512 546 Remote Computer(s) 544 510 FIG. 3 Patent Application Publication Sep. 17, 2009 Sheet 4 of 4 US 2009/0234804 A1

USER INTERFACE 640

NATIVE CODE 611 SOURCE CODE EDITOR 651 L COMPLER SOURCE 660 CODE 7N, COMPONENT 610 METADATA INTERMEDIATE 640 LANGUAGE SOURCE COMPONENT 650 || COMPLER1 COMMON LANGUAGE RUNTIME IDE 600 ENVIRONMENT 602

FIG. 4 US 2009/0234804 A1 Sep. 17, 2009

USING EXTENSION METHODS TO EXTEND oper, awkward program code, loss of desired language fea COMOBJECTS tures and an increase in programming errors.

BACKGROUND SUMMARY 0001 Years ago, in the infancy of the computer age, it was 0007 Extension methods are provided that use method not uncommon for a single programmer to write the entirety overloads that accept strongly-typed parameters, improving of a piece of software tailored to a particular task and even to type safety by allowing the compiler to enforce type safety a particular machine. Eventually, libraries of reusable pieces rather than relying on type checking at runtime. Nullable of code were developed so that already written and debugged types and object initialization may be used to provide code could be used again and again, thereby achieving effi strongly-typed optional parameters. Extension methods can ciencies in Software development. be used to support parameterized properties and to Support 0002. Object-oriented programming languages have class indexers, enabling query of collections of in-memory become very popular. An “object' in an object-oriented pro objects. gramming language is an encapsulated module of code and 0008. This Summary is provided to introduce a selection related data that is externally accessible through interfaces of concepts in a simplified form that are further described accessing well-defined and controlled connection points, below in the Detailed Description. This Summary is not known as the object's methods and properties. A collection of intended to identify key features or essential features of the objects can be created to perform the functions desired in a claimed subject matter, nor is it intended to be used to limit computer application. the scope of the claimed subject matter. 0003 Component Object Model (COM) is a platform for Software componentry used to enable interprocess communi BRIEF DESCRIPTION OF THE DRAWINGS cation and dynamic object creation in any programming lan 0009. In the drawings: guage that Supports the technology. The term COM is often 0010 FIG. 1 is a block diagram of an example of a system used in the software development world as an umbrella term that exposes extension methods for interfacing between that encompasses the OLE, OLE Automation, Active(R), objects and an application written in a managed code lan COM+ and DCOM technologies. COM provides a language guage in accordance with aspects of the Subject matter dis neutral way of implementing objects so an object can be used closed herein; in an environment different from the one in which it was 0011 FIG. 2 is a flow diagram of an example of a method created. for exposing extension methods for interfacing between 0004. A recent development in the computer world is the objects and an application written in a managed code lan creation of managed code environments. Managed code is guage in accordance with aspects of the Subject matter dis computer program code that executes under the management closed herein; of a virtual machine. In contrast, native (unmanaged) code is 0012 FIG. 3 is a block diagram illustrating an example of executed directly by a computer's central processing unit a computing environment in which aspects of the Subject (CPU). The programming language used to create the pro matter disclosed herein may be implemented; and gram determines whether it will run as managed code or as 0013 FIG. 4 is a block diagram of an example of an unmanaged code. Virtual machine environments can Support integrated development environment in accordance with many types of programming languages, including both aspects of the Subject matter disclosed herein. strongly-typed, early bound languages and loosely-typed lan guages. DETAILED DESCRIPTION 0005. When a program written in a strongly-typed lan guage calls an object using an interface written in a loosely Overview typed manner, incompatibilities Surface. In a loosely-typed, 0014 Microsoft(R) Visual Studio(R) is an Integrated Devel late-bound language the compiler does not do type-checking. opment Environment (IDE) that can be used to develop con Type incompatibilities are not detected until the program sole and GUI applications, Windows Forms applications, web executes. If a type incompatibility is detected when a program sites, web applications, and web services, etc. in native code is running, an exception is thrown. In contrast, a managed and in managed code. Visual Studio(R) Supports languages by code language may be a strongly-typed and early-boundlan means of language services, which allow any programming guage, meaning that the compiler does type-checking at com language to be supported by the code editor and debugger, if pile time. A program written in a strongly-typed program the language-specific service has been provided. Built-in lan ming language that makes a call to an object using an guages include C/C++ (via Visual C++(R), VB.NET (via interface written in a loosely-typed manner will lose the Visual Basic .NET), and C# (via Visual CHR). Support for advantages associated with compile-time type-checking. other languages such as FH, Python, and Ruby among others 0006. A loosely-typed object-oriented programming lan are also available via separately-installed language services. guage may make extensive use of optional parameters, vari Visual Studio(R) also supports XML/XSLT, HTML/XHTML, ant types, and parameterized properties. In contrast, a JavaScript and CSS. strongly-typed language may not support optional param 0015 The IDE is also responsible for coordinating and eters, named parameters, or parameterized properties. Some enabling communication between services. VSTO, or Visual times variant types are handled awkwardly in a strongly Studio Tools for Office is part of Microsoft's Visual Studio typed language. When a developer working in a strongly .NET tools suite and supports the Microsoft .NET Frame typed language calls an object in a shared library using an work. It is used by developers to write code connecting appli interface written in a loosely-typed manner, these language cations including but not limited to Microsoft Office Word, incompatibilities can result in increased work for the devel Excel and Outlook US 2009/0234804 A1 Sep. 17, 2009

0016 Automation is a formal inter-process communica objects in the model and which map the various automation tion mechanism based on COM that provides an infrastruc types to their managed code equivalents. The wrapper acts as ture so that an application (an automation controller) can an interface between its caller and the wrapped code. This access and manipulate (i.e., set properties of or call methods may be done for compatibility, e.g. if the wrapped code is in on) shared automation objects exported by other applications. a different programming language or uses different calling For example, a program being developed in Visual Studio(R) in conventions, or for security, e.g. to prevent the calling pro C# may set properties of or call methods on an Office object gram from executing certain functions. The implication is such as a Word Document. Automation objects can be written that the wrapped code can only be accessed via the wrapper. in conventional languages such as C++ or in languages Such An example of a PIA is an that comes with an object as Visual BasicR) and Borland Delphi. model such as Microsoft Office that allows managed code 0017. An automation object is a COM object implement (VB.NET, C#, etc.) to call Office code. For example, VSTO ing one or more interfaces (such as but not limited to the uses the PIAS to expose the Office object model to its add-ins IDispatch interface) between an automation object and a cli and document-level customizations. ent application. An interface provides a pointer to a virtual 0022. For example, the SaveAs method on the Word Docu function table that contains a list of pointers to the functions ment COM interface may be declared as follows: that implement the functions declared in the interface, in the same order that they are declared in the interface. The inter face exposes a method that allows methods of a class to be called by name, with an arbitrary number of parameters. HRESULT Save As( in, optional VARIANT * FileName, in, optional VARLANT * When called by a program written in a loosely-typed pro File:Format, in, optional VARIANT * LockComments, in, optional gramming language, neither the name of the method nor the VARIANT * Password, in, optional VARLANT * AddToRecentFiles, number (and exact types) of parameters needs to be known at in, optional VARIANT * WritePassword, in, optional VARIANT * compile time, because of late binding. For late binding, a ReadOnly Recommended, in, optional VARIANT * EmbedTrueTypeFonts, in, optional VARIANT * client only needs to know the name (or class identifier SaveNativePictureFormat, in, optional VARIANT * SaveFormsData, (CLSID)) of the desired object and the names and parameters in, optional VARIANT * SaveASAOCELetter, in, optional of methods it actually uses. VARIANT * Encoding, in, optional VARIANT * InsertLineBreaks, 0018. Implementing early binding is more troublesome. in, optional VARIANT * AllowSubstitutions, in, optional For early binding, the client needs to know the definition and VARIANT * LineEnding, in, optional VARIANT * FileAddBiDiMarks); interface identifier (IID) for each interface requested, as well as the position of each method in the interface 0023 Managed code languages like C#, derived from table. In order to automate an application, the developer of an strongly-typed and early-bound languages such as C++ and automation controller should know the object model that is Java, typically do not support optional parameters or param employed by that application. For that reason, among others, eterized properties. Variant parameters, used when the needed when Automation components are provided, they are usually data type can only be known at runtime, when the data type is accompanied by type libraries, which contain metadata about expected to vary, or when optional parameters and parameter classes, interfaces and other features exposed by an object arrays are desired, are also somewhat problematic in some library. managed code languages. For example, in managed code 0019 Type libraries are used to generate Proxy pattern/ languages such as C#, the variant type is replaced with the stub code for interoperating between COM and other plat object type. That is, a developer boxes parameters in objects, forms, such as Microsoft .NET and Java. For instance, the thereby losing the strongly-typed benefits of the language. .NET Framework SDK (Software Development Kit) includes Furthermore, some of the variant parameters may have to be tools that can generate a proxy .NET DLL to access Automa passed by reference. To do so, an intermediate, temporary tion objects using both early binding (with information about object is created on the Stack, is assigned to the value being interfaces extracted from a type library) and late binding (via passed to the object model and then the intermediate object is IDispatch, mapped to the .NET Reflection API), with the passed with a keyword (e.g., “ref) to indicate that the object built-in .NET-to-COM bridge called COM Interop. While being passed is a reference. There are no direct conversions Java lacks built-in COM support, toolsets like JACOB and between the two types. Segue can generate proxy source code (consisting of two 0024 Hence, an equivalent of the COM Save As method parts, a set of Java classes and a C++ Source for a Java Native declaration in the managed code language C#, may be: Interface DLL) from type libraries. 0020 Automation is available for a variety of languages, including, but not limited to C, C++ (directly or via a library void SaveAs( like MFC or ATL). Visual BasicR) and Visual Basic for Appli refobject FileName, cations, Delphi, Microsoft .NET languages, Java, JScript and refobject File:Format, refobject LockComments, refobject Password, VBScript, Perl, PHP, PowerBuilder and Ruby. refobject AddToRecentFiles, refobjectWritePassword, refobject 0021. An automation object model such as Microsoft ReadOnly Recommended, ref Office typically targets loosely-typed, late-bound languages object EmbedTrueTypeFonts, refobject SaveNativePictureFormat, such as VBA and Visual Basic and makes extensive use of refobject automation capabilities such as optional parameters (many of SaveFormsData, refobject SaveASAOCELetter, refobject Encoding, which are enumerated types), variant types, and parameter refobject InsertLineBreaks, refobject AllowSubstitutions, refobject LineEnding, ized properties. To expose the object model to a managed refobject code environment such as .NET, objects may be shipped with AddBiDiMarks) a set of assemblies (sometimes known as Primary Interop Assemblies or PIAS), which are thin wrappers around the US 2009/0234804 A1 Sep. 17, 2009

0025. In this method, “FileName” is the only logically object model accessed via an interface written in a loosely required parameter in the object model and the next 15 param typed manner to be accessed by a program written in a man eters are logically-optional parameters. All of the parameters aged code language that Supports extension methods. The for SaveAs are passed as references to objects. Because Cit programming language may not support optional parameters does not support optional parameters, a C# developer would (e.g., it may be a strongly-typed language). System 100 or have to write the following code to call the Chi Save As( ) method to save a document called “Foo.txt (i.e. to pass a portions thereofmay reside or bestored on a computer Such as value (“Foo.txt) stored in an object (FileName) as the first the computer described below with respect to FIG. 3. System parameter to the C# SaveAs method): 100 may be a part of an integrated development environment or may be separate from and/or accompany an integrated development environment such as the one described below with respect to FIG. 4. The integrated development environ object FileName = “Foo.txt: object missing = Type.Missing: ment may be a common language runtime (CLR) managed doc. Save AS(ref filename, ref missing, ref missing, ref missing, code environment. System 100 may include one or more of ref missing, ref missing, ref missing, refinissing, ref missing, ref missing, ref missing, the following: a programming language service 135, a library ref missing, ref of extension methods 115 and/or a library of objects 165 missing, ref missing, refinissing, ref missing); accessed via an interface 150 written in a loosely-typed man ner or an interface written in a strongly-typed manner that 0026. Because the managed code language C# does not exposes a method with one or more loosely-typed parameters. Support optional parameters, an object (called “missing) is 0029. Extension methods such as those in library 115 created boxing the parameter “Type. Missing. allow the association of new methods with a class other than All parameters are specified, even the "omitted ones. For those originally declared by the class. That is, extension example: methods make it possible to extend existing types with addi tional methods. Although the extension methods are not actu ally part of the class, they appear to a developer to be part of object FileName = “Foo.docx: the class. An extension method is declared as a static method object addBiDiMarks = true; but has a signature that identifies it as an extension of a object missing = Type. Missing: doc.Save AS (ref FileName, ref missing, ref missing, ref missing, ref particular identified class. For example, an extension method missing, ref missing, can be declared by specifying the keyword “this' as a modi ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, fier on the first parameter of the method. The managed lan ref missing, ref guage compiler looks at the object's type hierarchy for a missing, ref missing, refaddBiDiMarks); matching method when it is resolving method names. If no matching method is found, the compiler searches for exten instead of being able to only specify the desired parameters, sion methods declared for that type within a declared universe C.2. (e.g., Such as a universe of the namespaces included via “using statements). 0030. For example, a class Foo may be declared as: doc.Save AS(new DocumentSave ASArgs FileName = “Foo.docx': AddBiDiMarks = true public class Foo public void WriteHello () { System.Console.WriteLine(“Hello!"); } 0027. To address these and other issues encountered when interfacing an object model using an interface written in a loosely-typed manner or using a strongly-typed interface that while an extension to class Foo (FooExtensions) may be exposes a method with one or more loosely-typed parameters, declared as: and a calling program written in a strongly-typed language, (e.g., to enable a program written in a strongly-typed man aged code language to call objects using a loosely-typed public class FooExtensions interface) extension methods may be employed to provide { strongly-typed method overloads for the strongly-typed man public void WriteGoodbye(this Foo foo) { aged code equivalents of the loosely-typed method. Nullable System.Console.WriteLine("Goodbye!"); } types and object initialization may be used to provide strongly-typed optional parameters. Extension methods can be used to support parameterized properties and to Support 0031 Extension methods can enable more version-resil class indexers, enabling query of collections of in-memory ient code to be produced. For example, as an object model objects. evolves, new optional parameters are often added to the end of an interface method's parameter list. When this occurs, the Extension Methods for Shared Objects extension methods (e.g., library 115) can be updated and 0028 FIG. 1 illustrates an example of a system 100 that re-released so that user code which calls these methods does provides extension methods that allow objects in a shared not have to change. US 2009/0234804 A1 Sep. 17, 2009

0032. An extension method of the extension methods of 0043. Using extension methods, an overload method can library 115 may perform one or more of the following: be declared for the most common uses of a method. For 0033 receive a special “arguments’ object instance on example, one of the most common uses of the Microsoft Word which properties can be set as a part of the construction using Document SaveAS method is making a copy of a document. object initializers, The SaveAS method has one logically-required parameter 0034 set logically-optional parameters in a programming (the name of the document copy, e.g., FileName), and a num language that does not support optional parameters, ber of optional parameters. An overloaded method for Save As 0035 set parameterized properties in a programming lan may accept only the minimum number of parameters (e.g., guage that does not support parameterized properties, only required arguments, such as for example, the overloaded 0036 employ variant parameters without boxing param method may accept only the FileName parameter for making eters in objects, thereby maintaining the strongly-typed ben a copy of a document), and all the parameters may be efits of a programming language, strongly-typed. Logically-optional parameters having value 0037 employ variant parameters that are passed by refer types such as Boolean, or enumerations, may be nullable, ence without creating a temporary object, and passing a ref enabling a developer to pass a more natural and more erence to the object, strongly-typed “null instead of Type...Missing when omitting 0038 query, project and filter data in arrays, enumerable a value. classes, XML, relational database, and third party data 0044 An example of using the unextended Save As Sources, method follows: 0039 provide queries for a SQL-like query language used for filtering data in an e-mail and personal information man agement software product. object filename = “Foo.txt: 0040 Programming language package 135 of system 100 object missing = Type.Missing: may represent a language service including a program editor, doc.Save AS(ref filename, ref missing, ref missing, ref missing, user interface, and compiler. The programming language may ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, be a managed language that Supports extension methods such ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); as Visual Basic R or C#. The managed language may be a strongly-typed, late-bound programming language such as C# or other language that does not support optional param 0045 An example of an overloaded method in C# using eters, parameterized properties, use of variant parameters extensions for making a copy of a document may be declared without boxing, etc. as described above. A program 125 may S. be a program written in the programming language of the 0046. An example of an overloaded method in C# using package 135. Program 125 may call an object in library 165. extensions for making a copy of a document may be declared 0041 Library 165 represents a library of shared objects aS accessed via an interface 150 comprising a collection of methods by which the objects in library 165 are accessed. One Public static class DocumentExtensions or more of the shared objects such as object 1145, object 2 155, etc. in library 165 may be accessed via one or more of the public static void Save AS(this Document doc, string filename) methods exposed by the interface 150 and may be called by object fileNameCbi = filename: calling program 125. One or more of the methods exposed by object fileFormatObi = Type. Missing: the interface 150 may have optional parameters, parameter object addBiDiMarksObj= Type. Missing: ized properties, uses a variant parameter, etc. as described doc.SaveAS(ref fileNameCb, ref fileFormatObj,..., ref above. Interface 150 may itself be loosely-typed or strongly addBiDiMarksObj): typed. One or more of the methods exposed by the interface 150 may have one or more one loosely-typed parameters. Objects in library 165 may be automation objects as described above, exported or made available by applications 0047 Use of this method is greatly simplified, as demon including but not limited to Microsoft Word and Microsoft strated below. The CH code to save a document Foo.docx Outlook. using the SaveAS method extension to save a copy of the Strongly-Typed Method Overloads document may be: 0042 Extension methods can simplify the interface between objects in an object model and a program written in a strongly-typed programming language as described above if Save as new Word document... by providing method overloads that accept only required doc.SaveAs(“Foo.docx'); parameters or a Subset of parameters comprising a desired set of most commonly used combination of parameters. Over 0048 Similarly, an overload method using extensions for loaded methods also improve type safety by accepting converting a Word document to a different format may be strongly-typed parameters. For example, the use of an object declared as: or value indicating a missing parameter Such as Type. Missing is eliminated as is the need to pass parameters as objects. It will be appreciated that in the following description, Public static void SaveAs(this Document doc, string filename, examples are provided. The examples are meant to be illus WaSaveFormat? fileFormat) trative rather than limiting and the subject matter disclosed herein applies to any Suitable methods. US 2009/0234804 A1 Sep. 17, 2009

Use of this method is greatly simplified, as demonstrated 0.052 The following shows one possible implementation below. The C# code to save a document Foo.html using the of the method extension: SaveAS method extension that saves a copy of the document in a different format may be: public sealed class DocumentSave ASArgs : ExtensionArgs internal object FileNameInternal: if Save as new HTML document... internal object File:FormatInternal; doc.SaveAs(“Foo.html, WolSaveformat.wsFormathTML); internal object AddBiDiMarksInternal; public string FileName { Strongly-Typed Optional Parameters get { 0049 Strongly-typed optional parameters allow the natu return ToReference.(FileNameInternal); ral use of null for missing values. When a method (such as but Set not restricted to the SaveAs method described above) has a { large number of optional parameters or when there are no FileNameInternal = ToObject(value); common scenarios for which a Subset of parameters are actu ally specified, a single method override that accepts a single public WolSaveFormat? File:Format parameters class parameter can be provided. The class may { get contain or include a set of strongly-typed properties which { map in a one-to-one relationship with the parameters passed return ToValue.

could be created that accept the various property values. which is equivalent to: However, doing so for a large number of properties, each of which may or may not be set, is both tedious to write and tedious to use. Range Worksheet.Range(string ref) 0055 An example follows for the public class Foo having Range Worksheet.Range(string refl, string ref2) the following definition: 0061 An example of a traditional means for obtaining the Excel worksheet range is: public class Foo { public string HelloString get; set; } public string GoodbyeString get; set; } Range r1 = sheet.get Range(A1:B1, Type.Missing); Range r2 = sheet.get Rang(A1:“B1); public class Program { public void Main() An example of a new means for obtaining the Excel work { sheet range using extensions is:

0056. An example of the traditional method of initializa tion is: Range r3 = sheet.Range(A1:B1); Range ra. = sheet.Range(A1”, “B1);

// Old initialization style. 0062 An object model may expose collection class index Foo foo1 = new Foo(); ers via parameterized properties as well. When the indexer foo1. HelloString = “Hello!: Supports multiple index types, the syntax can become convo fool.GoodbyeString = "Goodbye!'; luted. The following example is the Word Documents object indexer, which allows indexing by both integer order and in which creating the objects HelloString and GoodbyeString document name: occur in separate steps. 0063 Document Documents.getItem(ref object index) 0064. This can be simplified by declaring the following 0057. In contrast, a special “arguments’ object instance on extension methods: which properties can be set as a part of the construction of the object using object initializers can be passed to the extension method as follows: public static Document Item (this Documents documentss, int index) { object indexObi = index: return documents.get Item (refindexObi); // New initialization style. Foo foo2 = new Foo { HelloString = “Hello!, GoodbyeString = public static Document Item (this Documents documents, string “Goodbye!" : fileName) { object fileNameCbi = fileName: return documents.get Item (ref fileNameCbi); in which creating the objects HelloString and GoodbyeString 0065. An example of a traditional means to obtain an open do not occur in separate steps. Word document is: Parameterized Properties 0058 Properties within an object model may take param object index = 1; object filename = “Foo.docx': eters. In the C# interface, properties with parameters are Document doc1 = app. Documents.get Item (refindex): converted to methods prefixed with get and set . Microsoft's Document doc2 = app. Documents.get Item (ref filename); Excel, for example, declares the following property: 0059 Range Worksheet.Range(object ref1, object ref2) 0.066 Extensions provide a consistent index API. Collec 0060. Because Cit does not support parameterized proper tion interfaces have an Item () extension method. More than ties, a C# developer accesses a parameterized property via its one extension method may be present for multiple types of get and set methods. For example: indicies. Indices for Item () extension methods are strongly typed. An example of a new means for obtaining an open Word document using extension methods is: Range Worksheet.get Range(object refl, object ref2) can be simplified by defining the following extension methods: public static Range Range(this Worksheet sheet, string ref) public static Range Range(this Worksheet sheet, string refl, string ref2) Document doc3 = app. Documents.Item (1): Document doc4 = app. Documents.Item (“Foo.docx'); US 2009/0234804 A1 Sep. 17, 2009

LINQ to Objects 0071. This enables the developer to write a query like the following: 0067 Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages using a syntax resembling var query = from store in stores.Items() SQL. LINQ declares a set of query operators that can be used where store.IsOpen to query, project and filter memory data encapsulated as select store.StoreID: objects in arrays, enumerable classes, XML, relational data bases, and third party data sources. Queries written using the query operators are executed either by the LINQ query pro LINQ to DASL cessing engine or, via an extension mechanism, handed over to LINQ providers which either implement a separate query 0072 The DAV Searching and Locating (DASL) query processing engine or translate to a different format to be language is a SQL-like query language used for filtering executed on a separate data store (such as on a database server e-mail and personal information (e.g., Outlook items). It will as SQL queries). The results of a query are returned as a be appreciated that although in the following description, collection of in-memory objects that can be enumerated. Outlook examples are provided, it will be understood that the subject matter described herein is not limited thereto and 0068 Collection classes in an object model may imple applies to any suitable information. Extension methods can ment the Ienumerable interface, which enables a compiler to provide a LINQ query provider for DASL by introducing an iterate over a collection of objects, however the type of the item class hierarchy with a common base case in which prop object is not known. A generic IEnumerable interface (de erties on classes correspond to DASL properties and where noted by ILEnumerable.) enables a compiler to iterate attributes attached to properties map to DASL properties. over a collection of objects of a known type. Extension meth Items of the item class include a property that returns an ods wrap collection classes implementing the IEnumerable underlying Outlook item. Classes can be extended to map to interface within an ILEnumerable. interface. homepostalladdress. These properties may generally map to 0069. Existing extension methods can generate an properties on the Outlook item interfaces, Mailltem.Subject IEnumerable. reference from an Ienumerable reference and ContactItem. HomeAddress, respectively. Programmatic (e.g. using the Cast interfaces on if the query syntax changes, all queries would need to be collections in an object model (e.g., Office), enabling queries located and potentially modified) and the readability of such to be written in a clean and consistent manner. For example, queries, especially as they become longer and more compli the Outlook Stores collection may have the following method cated, is reduced. All of these factors can make the generation extension: of DASL query strings difficult for a developer. 0075 A LINQ to DASL implementation using extension methods at runtime can generate an equivalent DASL query string from a LINQ expression written by a developer, pass it public static IEnumerable.

cationSource type performs queries across multiple folders. I0082. The LINQ to DASL implementation is extensible in Both types expose the IQueryable. and IQueryProvider that it allows the developer to add support for additional interfaces used by LINQ. Outlook item properties or a strongly-typed UserProperty. For example: public class ApplicationSource. : IQueryable., IQueryProvider {...} public class MyItem : OutlookItem public class ItemsSource.

I0083. The developer can then perform a query such as one public static IQueryable.) on a collection of objects or enabling querying of a collection of objects in memory. Extension methods may create an item 0080. The OutlookltemProperty Attribute above maps a class hierarchy with a common base case in which properties DASL property to a property on the Outlook item. The User on classes correspond to user-declared properties. The exten Properties property provides access to custom user properties sion method may call the underlying native method, passing declared on the item. (Reflection is used when dealing with the potentially altered parameters. At 308 the function called unknown Outlook item types.) The Item property is used to is executed and the results are returned to the calling program hold a reference to the underlying Outlook item. This can be used, for example, to create a projection of the Outlook items Example of a Suitable Computing Environment themselves rather than return the OutlookItem wrappers. I0085. In order to provide context for various aspects of the 0081. In addition to the standard Outlook item properties, subject matter disclosed herein, FIG. 3 and the following a developer can also query for a custom user property. For discussion are intended to provide a brief general description example, if the items have a boolean UserProperty called of a suitable computing environment 510 in which various “Is Archived', the following query could be used to retrieve embodiments may be implemented. While the subject matter the items in which the property is set to true. disclosed herein is described in the general context of com puter-executable instructions, such as program modules, executed by one or more computers or other computing devices, those skilled in the art will recognize that portions of var archivedItems = from item in folder.Items. AsOueryable () where (bool) item.UserProperties"IsArchived. Value the subject matter disclosed herein can also be implemented select item.Item; in combination with other program modules and/or a combi nation of hardware and Software. Generally, program mod ules include routines, programs, objects, components, data US 2009/0234804 A1 Sep. 17, 2009 structures, etc. that perform particular tasks or implement systems or devices such as remote computer(s) 544 provide particular data types. Typically, the functionality of the pro both input and output capabilities. gram modules may be combined or distributed as desired in 0090 Computer 512 can operate in a networked environ various embodiments. The operating environment 510 is only ment using logical connections to one or more remote com one example of a Suitable operating environment and is not puters, such as a remote computer(s) 544. The remote com intended to limit the scope of use or functionality of the puter 544 can be a personal computer, a server, a router, a subject matter disclosed herein. network PC, a peer device or other common network node, I0086. With reference to FIG.3, a general purpose comput and typically includes many or all of the elements described ing device in the form of a computer 512 is described. Com above relative to the computer 512, although only a memory puter 512 may include a processing unit 514, a system storage device 546 has been illustrated in FIG. 5. Remote memory 516, and a system bus 518. The processing unit 514 computer(s) 544 can be logically connected via communica can be any of various available processors. Dual micropro tion connection 550. Network interface 548 encompasses cessors and other multiprocessor architectures also can be communication networks such as local area networks (LANs) employed as the processing unit 514. The system memory and wide area networks (WANs) but may also include other 516 may include volatile memory 520 and nonvolatile networks. Communication connection(s) 550 refers to the memory 522. Nonvolatile memory 522 can include read only hardware/software employed to connect the network inter memory (ROM), programmable ROM (PROM), electrically face 548 to the bus 518. Connection 550 may be internal to or programmable ROM (EPROM) or flash memory. Volatile external to computer 512 and include internal and external memory 520 may include random access memory (RAM) technologies Such as modems (telephone, cable, DSL and which may act as external cache memory. The system bus 518 wireless) and ISDN adapters, Ethernet cards and so on. couples system components including the system memory 0091. It will be appreciated that the network connections 516 to the processing unit 514. The system bus 518 can be any shown are examples only and other means of establishing a of several types including a memory bus, memory controller, communications link between the computers may be used. peripheral bus, external bus, or local bus and may use any One of ordinary skill in the art can appreciate that a computer variety of available bus architectures. 510 or other client device can be deployed as part of a com 0087 Computer 512 typically includes a variety of com puter network. In this regard, the Subject matter disclosed puter readable media Such as Volatile and nonvolatile media, herein man pertain to any computer system having any num removable and non-removable media. Computer storage ber of memory or storage units, and any number of applica media may be implemented in any method or technology for tions and processes occurring across any number of storage storage of information Such as computer readable instruc units or Volumes. Aspects of the Subject matter disclosed tions, data structures, program modules or other data. Com herein may apply to an environment with server computers puter storage media includes, but is not limited to, RAM, and client computers deployed in a network environment, ROM, EEPROM, flash memory or other memory technology, having remote or local storage. Aspects of the Subject matter CDROM, digital versatile disks (DVD) or other optical disk disclosed herein may also apply to a standalone computing storage, magnetic cassettes, magnetic tape, magnetic disk device, having programming language functionality, inter storage or other magnetic storage devices, or any other pretation and execution capabilities. medium which can be used to store the desired information 0092 FIG. 4 illustrates an integrated development envi and which can be accessed by computer 512. ronment (IDE) 600 and Common Language Runtime Envi I0088. It will be appreciated that FIG.3 describes software ronment 602. An IDE 600 may allow a user (e.g., developer, that can act as an intermediary between users and computer programmer, designer, coder, etc.) to design, code, compile, resources. This Software may include an operating system test, run, edit, debug or build a program, set of programs, web 528 which can be stored on disk storage 524, and which can sites, web applications, and web services in a computer sys control and allocate resources of the computer system 512. tem. Software programs can include Source code (component System applications 530 take advantage of the management 610), created in one or more source code languages (e.g., of resources by operating system 528 through program mod Visual Basic R, Visual JiR, C++, C#, Ji, Java Script, APL, ules 532 and program data 534 stored either in system COBOL, Pascal, Eiffel, Haskell, ML, Oberon, Perl, Python, memory 516 or on disk storage 524. It will be appreciated that Scheme, and the like). The IDE 600 may provide a computers can be implemented with various operating sys managed code development environment using the .NET tems or combinations of operating systems. framework. An intermediate language component 650 may 0089. A user can enter commands or information into the be created from the source code component 610 and the computer 512 through an input device(s) 536. Input devices native code component 611 using a language specific source 536 include but are not limited to a pointing device such as a compiler 620 and the native code component 611 (e.g., mouse, trackball, stylus, touch pad, keyboard, microphone, machine executable instructions) is created from the interme and the like. These and other input devices connect to the diate language component 650 using the intermediate lan processing unit 514 through the system bus 518 via interface guage compiler 660 (e.g. just-in-time (JIT) compiler), when port(s) 538. An interface port(s) 538 may represent a serial the application is executed. That is, when an IL application is port, parallel port, universal serial bus (USB) and the like. executed, it is compiled while being executed into the appro Output devices(s) 540 may use the same type of ports as do priate machine language for the platform it is being executed the input devices. Output adapter 542 is provided to illustrate on, thereby making code portable across several platforms. that there are some output devices 540 like monitors, speakers Alternatively, in other embodiments, programs may be com and printers that require particular adapters. Output adapters piled to native code machine language (not shown) appropri 542 include but are not limited to video and sound cards that ate for its intended platform. provide a connection between the output device 540 and the 0093. A user can create and/or edit the source code com system bus 518. It should be noted that other devices and/or ponent according to known Software programming tech US 2009/0234804 A1 Sep. 17, 2009

niques and the specific logical and syntactical rules associ 4. The method of claim 1, wherein at least one parameter is ated with a particular source language via a user interface 640 specified in the call and wherein the extension method Sup and a source code editor 651 in the IDE 600. Thereafter, the plies unspecified optional parameters. Source code component 610 can be compiled via a source 5. The method of claim 1, wherein a parameter of the compiler 620, whereby an intermediate language representa extension method is specified as null. tion of the program may be created, such as assembly 630. The assembly 630 may comprise the intermediate language 6. The method of claim 1, wherein the extension method component 650 and metadata 640. Application designs may returns an enumerable type of a queried collection. be able to be validated before deployment. 7. The method of claim 1, wherein an object initializer 0094. The various techniques described herein may be initializes an instance of a parameter class, wherein the implemented in connection with hardware or Software or, instance is passed to the extension method. where appropriate, with a combination of both. Thus, the 8. A system comprising: methods and apparatus described herein, or certain aspects or portions thereof, may take the form of program code (i.e., a library of extension methods stored on a computer, the instructions) embodied in tangible media, Such as floppy dis library of extension methods comprising at least one kettes, CD-ROMs, hard drives, or any other machine-read extension method for a COM object of a plurality of able storage medium, wherein, when the program code is extension methods, the at least one extension method loaded into and executed by a machine, such as a computer, comprising a strongly-typed equivalent of a loosely the machine becomes an apparatus for practicing aspects of typed interface or a strongly-typed equivalent of a the Subject matter disclosed herein. In the case of program method with at least one loosely-typed parameter, the at code execution on programmable computers, the computing least one extension method accessed by a calling pro device will generally include a processor, a storage medium gram Written in a managed code programming language readable by the processor (including volatile and non-volatile memory and/or storage elements), at least one input device, Supporting extension methods. and at least one output device. One or more programs that 9. The system of claim 8, further comprising a common may utilize the creation and/or implementation of domain language runtime managed code environment in which the specific programming models aspects, e.g., through the use of library of extension methods is used. a data processing API or the like, may be implemented in a 10. The system of claim 8, wherein the managed program high level procedural or object oriented programming lan ming language is a strongly-typed language. guage to communicate with a computer system. However, the program(s) can be implemented in assembly or machinelan 11. The system of claim 8, wherein the at least one exten guage, if desired. In any case, the language may be a compiled sion method accepts required parameters and Supplies default or interpreted language, and combined with hardware imple values for non-required parameters. mentations. 12. The system of claim 8, wherein the at least one exten 0095 While the subject matter disclosed herein has been sion method accepts a single parameters class parameter, described in connection with the figures, it is to be understood wherein a class of the parameters comprise strongly-typed that modifications may be made to perform the same func parameters. tions in different ways. 13. The system of claim 8, wherein an object initializer initializes an instance of a parameter class, wherein the instance is passed to the at least one extension method. What is claimed: 14. The system of claim 8, wherein the at least one exten 1. A method of calling a COM object comprising: sion method provides null unification on a type level for all receiving a call to a method of the COM object from a types, the extension method boxing a value in a temporary calling program Written in a managed programming lan object and passing a reference to the temporary object. guage that Supports extension methods, using a loosely 15. A computer-readable storage medium comprising typed interface or using a strongly-typed interface com prising a method with at least one loosely-typed computer-executable instructions that when executed cause a parameter; computing environment to: determining an extension method associated with the receive a call to a method of an object from a calling called method of the COM object, the extension method program Written in a managed programming language providing a strongly-typed method overload for a that Supports extension methods, using a loosely-typed strongly-typed equivalent of the loosely-typed interface interface or using a strongly-typed interface comprising or providing a strongly-typed equivalent of the method a method with at least one loosely-typed parameter; with the at least one loosely-typed parameter, determining an extension method associated with the executing the extension method; and called method of the object, the extension method pro returning a result of executing the extension method to the viding a strongly-typed method overload for a strongly calling program. typed equivalent of the loosely-typed interface or pro 2. The method of claim 1, wherein the managed program viding a strongly-typed equivalent of the method with ming language is a strongly-typed programming language. the at least one loosely-typed parameter, 3. The method of claim 1, wherein the calling program is executing the extension method; and executed in a managed code environment comprising a com returning a result of executing the extension method to the mon language runtime. calling program. US 2009/0234804 A1 Sep. 17, 2009

16. The computer-readable storage medium of claim 15, a query string for an equivalent of an expression is gener comprising further computer-executable instructions such ated, wherein the expression queries a collection of in that when the extension method is executed: memory objects and wherein the query string queries e-mail information. properties are set on a new instance of an object as part of 19. The computer-readable storage medium of claim 15, a construction process using object initializers. comprising further computer-executable instructions such 17. The computer-readable storage medium of claim 15, that when the extension method is executed: comprising further computer-executable instructions such filter data in arrays or enumerable classes. that when the extension method is executed: 20. The computer-readable storage medium of claim 15, comprising further computer-executable instructions an enumerable type of a queried collection of in-memory wherein the extension method: objects is returned. accepts required parameters and Supplies default values for 18. The computer-readable storage medium of claim 15, non-required parameters. comprising further computer-executable instructions such that when the extension method is executed: c c c c c