Inspired by this article from Kai, I was tried to extend classes for the .Net Compact Framework with methods for the .Net Framework.
I had to work with graphics on the .Net Compact Framework. The opportunities in .Net Compact Framework are a little bit rare. So I decided to handle a part of the functionality on the desktop.
During my work, I created a class, which originally based on an older idea of myself. On the .Net Compact Framework it is not possible to open images as 32BitARGB image. The color-values for RGB are Ok, but the Alpha-information will be ignored by the .Net Compact Framework.
Now, I created an application for the Desktop, which uses the .Net Compact Framework-class. I wanted that, because I don’t want to have redundant source code for both applications. So I tried to extend the existing class with some methods for the Desktop .Net Framework. The new extended methods contains source code for the Desktop including all opportunities and advantages.
Let’s start now…
I added two projects to a solution. One for the Desktop-Framework, the other for the .Net Compact Framework.
Both projects had the same default namespace (green boxes) but a different assembly name (red boxes).
This are the properties of the base class:
and this are the properties of the extended class:
At next you need a reference to the base class in the extended class.
When you want to use both classes, the base- and the extended class in an other project you have to create a reference to both classes. Additionally, you have to insert a using-statement in each of the source code files where you want to use it.
Summary
Extensions for C#-classes are a fine nice feature. Especially when you could use it over/on different platforms. I used that for my project on www.codeplex.com.
No comments:
Post a Comment