2

I'm trying to use C# XML comments in conjunction with conditional directive.

With #if SYMBOL it works:

    /// <summary>Some summary.</summary>
    #if SYMBOL
    /// <remarks>Conditional remark</remarks>
    #endif
    public bool IsSupported { get; set; }

With negative preprocessor directive #if !SYMBOL it does not work:

    /// <summary>Some summary.</summary>
    #if !SYMBOL
    /// <remarks>Conditional remark</remarks>
    #endif
    public bool IsSupported { get; set; }

It produces following warning: XML comment is not placed on a valid language element. Moreover it includes the remarks element, but removes the summary element from the resulting XML documentation.

Update

With #if and #else blocks results are similar to #if !SYMBOL. Same warning produced by a summary element and no summary in the output.

    /// <summary>Some summary.</summary>
    #if SYMBOL
    /// <remarks>SYMBOL defined</remarks>
    #else
    /// <remarks>SYMBOL not defined</remarks>
    #endif
    public bool IsSupported { get; set; }

Any workaround for this? I'm using VS 2010 and C# 4.0.

6
  • Does putting the comment in an #else clause work? Commented Nov 25, 2014 at 14:22
  • With #else the result is similar to #if !SYMBOL. I've updated question with details. Commented Nov 25, 2014 at 14:42
  • I suspect that #if results in a newline... Commented Nov 25, 2014 at 16:08
  • I just tried this (VS2010 SP1, c# 4.0) using DEBUG as the symbol and I did not get any warnings. Commented Nov 25, 2014 at 16:44
  • Look at How to use #if in an XML comment for a possible solution. Commented Nov 18, 2021 at 8:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.