Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Extension methods on PocketPC Windows CE

Are extension methods available on CE framework as well? I have an extension method for string that works fine in a windows forms project, however it wont build in PocketPC application.

I figured this would be an easy thing to find out, however I was unable to find any info regarding extension methods on PocketPC.

Edit: Ooops this was my mistake. I wrote the extension method in Visual Studio 2008, however the PocketPC project was being compiled in Visual Studio 2005, which I didn't realised. Well that's a hour of my life I'm never getting back. Thanks everyone for answers anyway.

like image 664
David Božjak Avatar asked Jun 10 '09 13:06

David Božjak


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.


2 Answers

Wanted to clear up a bit of confusion here. Extension methods are a feature of the compiler, not necessarily a particular version of the framework. Therefore, extension methods can be used on any platform where there is a version of the compiler that supports both extension methods and that platform.

The C# 3.0 compiler can down target to 2.0 frameworks and supports extension methods so they should be available on the compact framework.

The only thing the framework actually provides for extension methods is the ExtensionAttribute. However this doesn't have any functionality associated with it and can be defined by your application if it's not available. Here is a blog post I wrote on the subject

  • http://blogs.msdn.com/jaredpar/archive/2007/11/16/extension-methods-without-3-5-framework.aspx
like image 183
JaredPar Avatar answered Oct 10 '22 02:10

JaredPar


Yes, they are supported in CF 3.5. If you are using CF 2.0 you will need to define the ExtensionAttribute and then they will work.

    // this is a definition of a 3.5 class for use in 2.0.  If we upgrade to target CF3.5, we will need to remove it...
    namespace System.Runtime.CompilerServices 
    { 
        public class ExtensionAttribute : Attribute { } 
    }

namespace TestExtension
{
    public static class Extensions
    {
        public static int TestMethod(this string value)
        {
            return value.ToString();
        }
    }
}
like image 3
Jack Bolding Avatar answered Oct 10 '22 03:10

Jack Bolding