13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>C#</strong> LANGUAGE SPECIFICATION• The pp-expressions of the #if and #elif directives are evaluated in order until one yields true. If anexpression yields true, the conditional-section of the corresponding directive is selected.• If all pp-expressions yield false, and if an #else directive is present, the conditional-section of the #elsedirective is selected.• Otherwise, no conditional-section is selected.The selected conditional-section, if any, is processed as a normal input-section: the source code contained in thesection must adhere to the lexical grammar; tokens are generated from the source code in the section; and preprocessingdirectives in the section have the prescribed effects.The remaining conditional-sections, if any, are processed as skipped-sections: except for pre-processingdirectives, the source code in the section need not adhere to the lexical grammar; no tokens are generated fromthe source code in the section; and pre-processing directives in the section must be lexically correct but are nototherwise processed. Within a conditional-section that is being processed as a skipped-section, any nestedconditional-sections (contained in nested #if...#endif and #region...#endregion constructs) are alsoprocessed as skipped-sections.[Example: The following example illustrates how conditional compilation directives can nest:#define Debug // Debugging on#undef Trace // Tracing offclass PurchaseTransaction{void Commit() {#if DebugCheckConsistency();#if TraceWriteToLog(this.ToString());#endif#endifCommitHelper();}…}Except for pre-processing directives, skipped source code is not subject to lexical analysis. For example, thefollowing is valid despite the unterminated comment in the #else section:#define Debug // Debugging onclass PurchaseTransaction{void Commit() {#if DebugCheckConsistency();#else/* Do something else#endif}…}Note, however, that pre-processing directives are required to be lexically correct even in skipped sections ofsource code.Pre-processing directives are not processed when they appear inside multi-line input elements. For example, theprogram:66

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!