MSDN Magazine - July 2008 - (Page 18) I use the first line, AddInStore.Update, to method implementation). I will explain search for available add-ins and pipeline the significance of this later. components. PipelineStoreLocation.ApFigure 4 shows what the host view plicationBase tells it to look in the applilooks like for the ShapeApplication obcation’s folder. For a detailed description ject. The types used in members can eiof the folder structure, see go.microsoft.com/ ther be built-in framework types, such as fwlink/?LinkId=117521. Next, I get the type of EventHandler , or other views, such the add-ins I want to activate. In this case as IDrawing. You can download FxCop it’s the IShapeAddIn type defined in the rules from our CodePlex site at go.micro soft.com/fwlink/?LinkId=117524 to verify that host views assembly. Finally, I call AddInStore.FindAddIns, which returns a Figure 3 The Add-In Manager Form the views are easily adaptable into a comcollection of available add-in tokens that plete pipeline. I can inspect and activate. Once I have selected a token from the Once I have created the views assembly, I modify the host’s classcollection, I can use one line of code to activate it: es to inherit from corresponding views. The changes to the Shape// activate the add-in in full trust mode Application class are shown here in red: ShapeAppHostViews.IShapeAddIn addIn = token.Activate ( AddInSecurityLevel.FullTrust); I can also choose to activate add-ins out of process or under a different trust level. For a list of isolation levels, you can go to go.microsoft.com/fwlink/?LinkId=117522. For a performance comparison of isolation levels, see the blog post on performance, available at go.microsoft.com/fwlink/?LinkId=117523. public class ShapeApplication : System.Windows.Forms.IWin32Window { } public class ShapeApplication : ShapeAppHostViews.IShapeApplication, System.Windows.Forms.IWin32Window { } Exposing the Object Model Once the empty pipeline and add-in manager are in place, I can start exposing functionality from the host to the add-in. To expose the types included in the object model, I need to first create a host view in the HostViews assembly for each type that I want to expose. I can expose properties, methods, and events in the view. The host view can be either an abstract base class or an interface. In the ShapeApp, I have used interfaces for three reasons. First, they are needed for events to work correctly when used from Visual Basic®. Second, C# does not support multiple inheritance, so a class cannot inherit from two base classes. Therefore, the view should be an interface to allow all host classes to implement it (even if they already have a base). Third, interfaces allow EIMI (explicit interface Figure 4 ShapeApplication Object Host View namespace ShapeAppHostViews { public interface IShapeApplication { // the drawing present in the selected tab IDrawing ActiveDrawing { get; } // a collection of available shapes (square, circle, etc) IShapeCollection AvailableShapes { get; } // a collection of drawings currently open in the application IDrawingCollection Drawings { get; } // main window visibility bool Visible { get; set; } // create a new drawing in the application IDrawing NewDrawing(); // completely exit the application void Quit(); // event fired when a drawing is created event EventHandler CreatedDrawing; Next, I need to implement each member from the host view. For members that use built-in types as arguments and return values, there is no special implementation required (other than ensuring the member is public in the host’s class). For example, the Visible property in the ShapeApplication class has the same signature as the Visible interface member: public bool Visible { get { } set { } } This means that the existing implementation of Visible in the host’s ShapeApplication class will be used as the view implementation. However, members that use other types defined in the host views need to be implemented explicitly. For example, the ActiveDrawing property has different signatures in the ShapeApplication class and in the IShapeApplication host view. The original version in the host’s class returns a Drawing object: public Drawing ActiveDrawing { get { } } The version in the host view, IShapeApplication, can only return the corresponding view, IDrawing: IDrawing ActiveDrawing { get; } } } To implement the second version in the host’s class, I need to use EIMI. I do this by adding a new property in the host’s class with the same name, ActiveDrawing. Now the host’s ShapeApplication class has two properties called ActiveDrawing (see Figure 5). The new implementation implicitly casts the Drawing object to the IDrawing type. If you are exposing an object model for a Windows Forms application, it is likely that some of the exposed CLR Inside Out 18 msdn magazine http://go.microsoft.com/fwlink/?LinkId=117521 http://go.microsoft.com/fwlink/?LinkId=117521 http://go.microsoft.com/fwlink/?LinkId=117524 http://go.microsoft.com/fwlink/?LinkId=117524 http://go.microsoft.com/fwlink/?LinkId=117522 http://go.microsoft.com/fwlink/?LinkId=117523
Table of Contents Feed for the Digital Edition of MSDN Magazine - July 2008 MSDN Magazine - July 2008 Contents Toolbox CLR Inside Out Flex Your Data Data Points Advanced Basics Office Space Cutting Edge Data Services ADO.NET Data and WPF Transactions WCF P2P Test Run Security Briefs Foundations .NET Matters {End Bracket} MSDN Magazine - July 2008 MSDN Magazine - July 2008 - (Page Intro) MSDN Magazine - July 2008 - Contents (Page Cover1) MSDN Magazine - July 2008 - Contents (Page Cover2) MSDN Magazine - July 2008 - Contents (Page 1) MSDN Magazine - July 2008 - Contents (Page 2) MSDN Magazine - July 2008 - Contents (Page 3) MSDN Magazine - July 2008 - Contents (Page 4) MSDN Magazine - July 2008 - Contents (Page 5) MSDN Magazine - July 2008 - Contents (Page 6) MSDN Magazine - July 2008 - Contents (Page 7) MSDN Magazine - July 2008 - Contents (Page 8) MSDN Magazine - July 2008 - Contents (Page 9) MSDN Magazine - July 2008 - Contents (Page 10) MSDN Magazine - July 2008 - Toolbox (Page 11) MSDN Magazine - July 2008 - Toolbox (Page 12) MSDN Magazine - July 2008 - Toolbox (Page 13) MSDN Magazine - July 2008 - Toolbox (Page 14) MSDN Magazine - July 2008 - Toolbox (Page 15) MSDN Magazine - July 2008 - Toolbox (Page 16) MSDN Magazine - July 2008 - CLR Inside Out (Page 17) MSDN Magazine - July 2008 - CLR Inside Out (Page 18) MSDN Magazine - July 2008 - CLR Inside Out (Page 19) MSDN Magazine - July 2008 - CLR Inside Out (Page 20) MSDN Magazine - July 2008 - CLR Inside Out (Page 21) MSDN Magazine - July 2008 - CLR Inside Out (Page 22) MSDN Magazine - July 2008 - CLR Inside Out (Page 23) MSDN Magazine - July 2008 - CLR Inside Out (Page 24) MSDN Magazine - July 2008 - Data Points (Page 25) MSDN Magazine - July 2008 - Data Points (Page 26) MSDN Magazine - July 2008 - Data Points (Page 27) MSDN Magazine - July 2008 - Data Points (Page 28) MSDN Magazine - July 2008 - Data Points (Page 29) MSDN Magazine - July 2008 - Data Points (Page 30) MSDN Magazine - July 2008 - Data Points (Page 31) MSDN Magazine - July 2008 - Data Points (Page 32) MSDN Magazine - July 2008 - Data Points (Page 33) MSDN Magazine - July 2008 - Data Points (Page 34) MSDN Magazine - July 2008 - Advanced Basics (Page 35) MSDN Magazine - July 2008 - Advanced Basics (Page 36) MSDN Magazine - July 2008 - Advanced Basics (Page 37) MSDN Magazine - July 2008 - Advanced Basics (Page 38) MSDN Magazine - July 2008 - Advanced Basics (Page 39) MSDN Magazine - July 2008 - Advanced Basics (Page 40) MSDN Magazine - July 2008 - Advanced Basics (Page 41) MSDN Magazine - July 2008 - Advanced Basics (Page 42) MSDN Magazine - July 2008 - Office Space (Page 43) MSDN Magazine - July 2008 - Office Space (Page 44) MSDN Magazine - July 2008 - Office Space (Page 45) MSDN Magazine - July 2008 - Office Space (Page 46) MSDN Magazine - July 2008 - Office Space (Page 47) MSDN Magazine - July 2008 - Office Space (Page 48) MSDN Magazine - July 2008 - Office Space (Page 49) MSDN Magazine - July 2008 - Office Space (Page 50) MSDN Magazine - July 2008 - Cutting Edge (Page 51) MSDN Magazine - July 2008 - Cutting Edge (Page 52) MSDN Magazine - July 2008 - Cutting Edge (Page 53) MSDN Magazine - July 2008 - Cutting Edge (Page 54) MSDN Magazine - July 2008 - Cutting Edge (Page 55) MSDN Magazine - July 2008 - Cutting Edge (Page 56) MSDN Magazine - July 2008 - Cutting Edge (Page 57) MSDN Magazine - July 2008 - Data Services (Page 58) MSDN Magazine - July 2008 - Data Services (Page 59) MSDN Magazine - July 2008 - Data Services (Page 60) MSDN Magazine - July 2008 - Data Services (Page 61) MSDN Magazine - July 2008 - Data Services (Page 62) MSDN Magazine - July 2008 - Data Services (Page 63) MSDN Magazine - July 2008 - Data Services (Page 64) MSDN Magazine - July 2008 - Data Services (Page 65) MSDN Magazine - July 2008 - Data Services (Page 66) MSDN Magazine - July 2008 - Data Services (Page 67) MSDN Magazine - July 2008 - Data Services (Page 68) MSDN Magazine - July 2008 - Data Services (Page 69) MSDN Magazine - July 2008 - ADO.NET (Page 70) MSDN Magazine - July 2008 - ADO.NET (Page 71) MSDN Magazine - July 2008 - ADO.NET (Page 72) MSDN Magazine - July 2008 - ADO.NET (Page 73) MSDN Magazine - July 2008 - ADO.NET (Page 74) MSDN Magazine - July 2008 - ADO.NET (Page 75) MSDN Magazine - July 2008 - ADO.NET (Page 76) MSDN Magazine - July 2008 - ADO.NET (Page 77) MSDN Magazine - July 2008 - Data and WPF (Page 78) MSDN Magazine - July 2008 - Data and WPF (Page 79) MSDN Magazine - July 2008 - Data and WPF (Page 80) MSDN Magazine - July 2008 - Data and WPF (Page 81) MSDN Magazine - July 2008 - Data and WPF (Page 82) MSDN Magazine - July 2008 - Data and WPF (Page 83) MSDN Magazine - July 2008 - Data and WPF (Page 84) MSDN Magazine - July 2008 - Data and WPF (Page 85) MSDN Magazine - July 2008 - Data and WPF (Page 86) MSDN Magazine - July 2008 - Data and WPF (Page 87) MSDN Magazine - July 2008 - Data and WPF (Page 88) MSDN Magazine - July 2008 - Data and WPF (Page 89) MSDN Magazine - July 2008 - Data and WPF (Page 90) MSDN Magazine - July 2008 - Transactions (Page 91) MSDN Magazine - July 2008 - Transactions (Page 92) MSDN Magazine - July 2008 - Transactions (Page 93) MSDN Magazine - July 2008 - Transactions (Page 94) MSDN Magazine - July 2008 - Transactions (Page 95) MSDN Magazine - July 2008 - Transactions (Page 96) MSDN Magazine - July 2008 - Transactions (Page 97) MSDN Magazine - July 2008 - Transactions (Page 98) MSDN Magazine - July 2008 - Transactions (Page 99) MSDN Magazine - July 2008 - Transactions (Page 100) MSDN Magazine - July 2008 - Transactions (Page 101) MSDN Magazine - July 2008 - Transactions (Page 102) MSDN Magazine - July 2008 - Transactions (Page 103) MSDN Magazine - July 2008 - Transactions (Page 104) MSDN Magazine - July 2008 - WCF P2P (Page 105) MSDN Magazine - July 2008 - WCF P2P (Page 106) MSDN Magazine - July 2008 - WCF P2P (Page 107) MSDN Magazine - July 2008 - WCF P2P (Page 108) MSDN Magazine - July 2008 - WCF P2P (Page 109) MSDN Magazine - July 2008 - WCF P2P (Page 110) MSDN Magazine - July 2008 - Test Run (Page 111) MSDN Magazine - July 2008 - Test Run (Page 112) MSDN Magazine - July 2008 - Test Run (Page 113) MSDN Magazine - July 2008 - Test Run (Page 114) MSDN Magazine - July 2008 - Test Run (Page 115) MSDN Magazine - July 2008 - Test Run (Page 116) MSDN Magazine - July 2008 - Security Briefs (Page 117) MSDN Magazine - July 2008 - Security Briefs (Page 118) MSDN Magazine - July 2008 - Security Briefs (Page 119) MSDN Magazine - July 2008 - Security Briefs (Page 120) MSDN Magazine - July 2008 - Security Briefs (Page 121) MSDN Magazine - July 2008 - Security Briefs (Page 122) MSDN Magazine - July 2008 - Foundations (Page 123) MSDN Magazine - July 2008 - Foundations (Page 124) MSDN Magazine - July 2008 - Foundations (Page 125) MSDN Magazine - July 2008 - Foundations (Page 126) MSDN Magazine - July 2008 - Foundations (Page 127) MSDN Magazine - July 2008 - Foundations (Page 128) MSDN Magazine - July 2008 - Foundations (Page 129) MSDN Magazine - July 2008 - Foundations (Page 130) MSDN Magazine - July 2008 - .NET Matters (Page 131) MSDN Magazine - July 2008 - .NET Matters (Page 132) MSDN Magazine - July 2008 - .NET Matters (Page 133) MSDN Magazine - July 2008 - .NET Matters (Page 134) MSDN Magazine - July 2008 - .NET Matters (Page 135) MSDN Magazine - July 2008 - {End Bracket} (Page 136) MSDN Magazine - July 2008 - {End Bracket} (Page Cover3) MSDN Magazine - July 2008 - {End Bracket} (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.