Avatar billede _just4fun_ Nybegynder
13. august 2003 - 21:10 Der er 7 kommentarer og
1 løsning

Conditional("DEBUG")

Gad vide hvad det er...
Avatar billede nielslbeck Nybegynder
13. august 2003 - 21:18 #1
Hæ hæ... ret sjov måde at gøre det på :-)

Men måske skulle du lige smide et link til http://www.eksperten.dk/spm/387206 så folk ved hvad det drejer sig om :-)
Avatar billede a1a1 Novice
13. august 2003 - 21:21 #2
Fra .net hjælp...(har du ikke det)

Marks a conditional method whose execution depends on a specified preprocessing identifier.

[Conditional(
  conditionalSymbol
)]
Parameters
conditionalSymbol
A string representing the name of a preprocessing identifier.
Applies To
Method declarations.

Remarks
The Conditional attribute is a multiuse attribute. Conditional is an alias for System.Diagnostics.ConditionalAttribute.

Wherever a conditional method is called, the presence or absence of the preprocessing symbol specified by conditionalSymbol at the point of the call determines whether the call is included or omitted. If the symbol is defined, the call is included; otherwise, the call is omitted. Conditional methods provide a cleaner, more elegant alternative to enclosing the method call in #if conditionalSymbol...#endif preprocessor directives.

A conditional method must be a method in a class or struct declaration and must have a return type of void (for other restrictions, see 17.4.2 The Conditional attribute).

If a method has multiple Conditional attributes, a call to the method is included if at least one of the conditional symbols is defined (in other words, the symbols are logically ORed together).

[Conditional("A"), Conditional("B")] public static void IfAorB( )
{
  ...
}
To achieve the effect of logically ANDing symbols, you can define serial conditional methods:

[Conditional("A")] public static void IfAandB( )
{
  AandBPrivate( );
}
[Conditional("B")] static void AandBPrivate( )
{
  /* Code to execute when both A and B are defined... */
}
Call IfAandB; if both A and B are defined, AandBPrivate will execute.

Example
// cs_attribute_conditional.cs
#define DEBUG
using System;
using System.Diagnostics;
public class Trace
{
  [Conditional("DEBUG")] public static void Msg(string msg)
  {
      Console.WriteLine(msg);
  }
}
class Test
{
  static void A( )
  {
      Trace.Msg("Now in A.");
      B( );
  }
  static void B( )
  {
      Trace.Msg("Now in B.");
  }
  public static void Main( )
  {
      Trace.Msg("Now in Main.");
      A( );
      Console.WriteLine("Done.");
  }
}
Output
Now in Main.
Now in A.
Now in B.
Done.
If you compile the sample with first line omitted (or changed to #undef DEBUG), the output will be: Done..

;o)
Avatar billede _just4fun_ Nybegynder
13. august 2003 - 21:26 #3
> nb... ja, der havde du sku ret.. det tænkte jeg ikke lige på!!!
> a1 Sorry den alt for lidt forklarende overkrift.. det var egentlig point til cyberprofessor for http://www.eksperten.dk/spm/387206
Avatar billede a1a1 Novice
13. august 2003 - 21:27 #4
tsk....
Avatar billede _just4fun_ Nybegynder
13. august 2003 - 21:27 #5
men jo, jeg har .Net-hjælpen (men når den starter op, tager det et sted mellem 7-10 minutter(????)) Håber det bliver bedre når jeg installerer vs2003 her en af dagene.....
Avatar billede a1a1 Novice
13. august 2003 - 21:31 #6
det kan være din antivirus der fucker det op ;o)
Avatar billede burningice Nybegynder
13. august 2003 - 21:42 #7
guess we need a answer from me :)
Avatar billede _just4fun_ Nybegynder
13. august 2003 - 21:43 #8
over'nout
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester