Free mag vol1 | Page 650

CHAPTER 15  TYPE REFLECTION, LATE BINDING, AND ATTRIBUTE-BASED PROGRAMMING  Note Windows Forms was the initial desktop API of the .NET platform. However, since the release of .NET 3.0, the Windows Presentation Foundation (WPF) API is quickly becoming the preferred GUI framework. While this is true, I will make use of Windows Forms for a number of client GUI examples in this text, as the related code is a bit more intuitive than the corresponding WPF code. If you are not familiar with the process of building Windows Forms applications, feel free to simply open up the supplied sample code and follow along. To serve as a road map, our extendable application entails the following assemblies: • CommonSnappableTypes.dll: This assembly contains type definitions that will be used by each snap-in object and will be directly referenced by the Windows Forms application. • CSharpSnapIn.dll: A snap-in written in C#, which leverages the types of CommonSnappableTypes.dll. • VbSnapIn.dll: A snap-in written in Visual Basic, which leverages the types of CommonSnappableTypes.dll. • MyExtendableApp.exe: This Windows Forms application will be the entity that may be extended by the functionality of each snap-in. Again, this application will make use of dynamic loading, reflection, and late binding to dynamically gain the functionality of assemblies it has no prior knowledge of. Building CommonSnappableTypes.dll The first order of business is to create an assembly that contains the types that a given snap-in must leverage to be plugged into the expandable Windows Forms application. The CommonSnappableTypes Class Library project defines two types: namespace CommonSnappableTypes { public interface IAppFunctionality { void DoIt(); } [AttributeUsage(AttributeTargets.Class)] public sealed class CompanyInfoAttribute : System.Attribute { public string CompanyName { get; set; } public string CompanyUrl { get; set; } } } 592