添加示例代码后XML文档出错

时间:2014-01-13 19:46:04

标签: c# xml-documentation

我正在尝试为我编写的API编写一些文档。 C#编译器不会为此特定方法生成文档。它说XML文档格式不正确。

你能帮我辨认一下它的不良形象吗?我已多次检查代码,但我找不到问题。不幸的是,C#编译器不会告诉我哪一行导致了这个问题。

/// <summary>
/// Given a value pertaining to a specific culture, let's call it the value culture, 
/// this method returns a sequence of resource keys and their values in another culture, 
/// let's call this the desired culture, based on a search of matching values in the value culture. 
/// The search can further be filtered based on metadata.
/// </summary>
/// <typeparam name="T">Represents the System.Type of value to look up and return.</typeparam>
/// <param name="value">The value pertaining to a value culture to search for.</param>
/// <param name="valueCulture">The short name of the culture to which the value specified by the <paramref name="value"/> parameter belongs.</param>
/// <param name="desiredCulture">The short name of the culture in which matching resource keys and values are to be sought.</param>
/// <param name="metadata">Metadata to filter the search results with.</param>
/// <param name="defaultValue">A default value to be returned if no matching records are found.</param>
/// <returns>Returns an object of <see cref = "ReverseLookupResult{T}"/>, which contains all the search parameters and a sequence of matches.</returns>
/// <remarks>
/// <para>One of the most common scenarios when implementing internationalization in your software is this.</para>
/// 
/// <para>The application you want to internationalize has already been developed. Or at least a 
/// significant part of it has been developed and work is ongoing, and amidst the chaos, you 
/// have been asked to internationalize string resources.</para>
/// 
/// <para>In this scenario, you already have English strings in your application. It would be so much nicer and easier for you 
/// did not have remember resource keys but simply call a method to which you gave an English value and it gave you back the 
/// equivalent value in another culture of your choice. For e.g. if you wanted to translate your software into French, it would 
/// be so much nicer if you simply supplied to a method the value "Hello" in English and it returned to you "Bonjour". That way, 
/// you could simply call that method wherever the English strings were in your application without having to remember resource keys.</para>
/// 
/// <para>This is the primary need that this method fulfills.</para>
/// 
/// <example>
/// Consider this example. Suppose you had a program like so:
/// 
/// <code>
/// public void PrintMessage()
/// {
///     System.Console.WriteLine("Hello");
/// }
/// </code>
/// </example>
/// 
/// <example>
/// And you were asked to internatlize it to support French. You would use this method like so:
/// 
/// <code>
/// private string _desiredCulture = "fr-FR";
/// 
/// public void PrintMessage()
/// {
///     ResourceManager resourceManager = new ResourceManager("en-US");
///     
///     var reverseLookupResult = resourceManager.ReverseLookup("Hello", "en-US", 
///                                                 _desiredCulture, null, "Hello");
///                                                 
///     if (reverseLookupResult != null && reverseLookupResult.Matches.Count > 0)
///     {
///         System.Console.WriteLine(reverseLookupResult.Matches.First().Value);
///     }
/// }
/// </code>
/// </example>
/// 
/// </remarks>
public ReverseLookupResult<T> ReverseLookup<T>(T value, string valueCulture, string desiredCulture,
    IMetadata metadata, T defaultValue = default(T))

1 个答案:

答案 0 :(得分:5)

在这一行

///     if (reverseLookupResult != null && reverseLookupResult.Matches.Count > 0)

您使用&而不将其转发为&amp;。在XML中,普通&表示character reference的开头。以下内容解决了您的问题:

///     if (reverseLookupResult != null &amp;&amp; reverseLookupResult.Matches.Count > 0)

调试提示:删除行并重新编译,直到问题消失。如果您do that smartly,则会在O(log n)步骤中找到有问题的行。这就是我发现问题的方法。这不仅适用于XML文档,也适用于错误消息未指定违规行的所有其他情况。