[Mono-dev] Please, share your .Net1.1 and 2.0 support and #if directives experience

Rodrigo B. de Oliveira rodrigobamboo at gmail.com
Fri Feb 10 11:37:16 EST 2006


On 2/10/06, Francisco Figueiredo Jr. <fxjrlists at yahoo.com.br> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
>
> Hi all,
>

Hey!

> Npgsql developers are going to start adding 2.0 functionality and
> interfaces to Npgsql.
>
> We discussed about it and we decided to have another directory in Npgsql
> cvs tree to hold the new Npgsql2 source code.
>
> I'd like to hear from you what are your experience with usage of #if in
> the source code.
> ...

We've been using #if directives with success for some time now for the
db4o code base. The main benefit is that the code is always where you
expect it to be.

For complex scenarios we use a mix of partial classes and #if
directives, for instance:

// Baz.cs
namespace Foo.Bar
{
#if NET_2_0
partial
#endif
    class Baz
    {
         ... // code for all platforms goes here
    }
}

// Baz_2.cs
namespace Foo.Bar
{
#if NET_2_0
    partial class Baz
    {
       // Net 2 specific code here
    }
#endif
}

I would recommend against using #if directives inside a method body,
it's much better to have two versions of the method using 'Extract
Method' as appropriate to share functionality.

Rodrigo

PS: E aê, Chicão??!!! :)



More information about the Mono-devel-list mailing list