简体   繁体   English

由于注释中的 cref 引用,在 C# 应用程序中出现不明确的引用错误?

[英]Getting ambiguous reference error in C# app due to cref reference in comments?

This is a new problem I've never seen before.这是我以前从未见过的新问题。 It's occurring in an open source wrapper for LibCURL.NET:它发生在 LibCURL.NET 的开源包装器中:

http://sourceforge.net/projects/libcurl-net/ http://sourceforge.net/projects/libcurl-net/

I am getting an ambiguous reference "warning as error", but the odd part is that it's happening due to a CREF reference in one of the LibCURL source files (see below).我收到了一个模棱两可的参考“警告为错误”,但奇怪的是,它是由于 LibCURL 源文件之一中的 CREF 参考而发生的(见下文)。 There are indeed several different overloads for for the method named Easy.GetInfo() , but I have no idea how to fix this since the offending code isn't a method call to Easy.GetInfo(), in fact it isn't code at all, but instead it's a CREF element in the comments for an Enum.对于名为 Easy.GetInfo() 的方法确实有几种不同的重载,但我不知道如何解决这个问题,因为有问题的代码不是对 Easy.GetInfo() 的方法调用,实际上它不是代码根本没有,但它是 Enum 注释中的 CREF 元素。 Does anyone know how to fix this?有谁知道如何解决这一问题?

/// <summary>
/// This enumeration is used to extract information associated with an
/// <see cref="Easy"/> transfer. Specifically, a member of this
/// enumeration is passed as the first argument to
/// <see cref="Easy.GetInfo"/> specifying the item to retrieve in the
/// second argument, which is a reference to an <c>int</c>, a
/// <c>double</c>, a <c>string</c>, a <c>DateTime</c> or an <c>object</c>.
/// </summary>
public enum CURLINFO
{
    ...

Note: I re-targeted LibCURL.NET for the .NET framework version 4.5.1.注意:我将 LibCURL.NET 重新定位为 .NET 框架版本 4.5.1。 I am mentioning this in case it might be related.我提到这一点,以防它可能相关。

Got an answer on Twitter, my thanks to Peter Foot.在 Twitter 上得到了答案,感谢 Peter Foot。 It's really an obscure solution so I'm putting it here for others to find as a community Wiki answer.这确实是一个晦涩的解​​决方案,所以我将它放在这里供其他人作为社区 Wiki 答案找到。 All I had to do was prefix the CREF target with "o:" and that tells the compiler to accept the reference to an overloaded function.我所要做的就是在 CREF 目标前面加上“o:”,这告诉编译器接受对重载函数的引用。 See below:见下文:

    /// <summary>
    /// Pass a <c>bool</c>. If it is <c>true</c>, libcurl will attempt to get
    /// the modification date of the remote document in this operation. This
    /// requires that the remote server sends the time or replies to a time
    /// querying command. The <see cref="o:Easy.GetInfo"/> function with the
    /// <see cref="CURLINFO.CURLINFO_FILETIME"/> argument can be used after a
    /// transfer to extract the received time (if any).
    /// </summary>

Also answering for history: You can reference a specific overloaded function by specifying its parameters.还回答历史:您可以通过指定其参数来引用特定的重载函数。

For example, say your Easy.GetInfo had an overload that takes an int as a parameter.例如,假设您的Easy.GetInfo有一个将 int 作为参数的重载。 You could reference that specific function with <see cref="Easy.GetInfo(int)"/> .您可以使用<see cref="Easy.GetInfo(int)"/>引用该特定函数。 It seems the o: thing "breaks the reference", so to speak.可以这么说,似乎o:事情“破坏了参考”。 (I did not go into the details of this.) (我没有详细介绍这个。)

Also, in the case where your parameters type involve generics you'll have to escape the < and > characters.此外,在您的参数类型涉及泛型的情况下,您必须对<>字符进行转义。 In my case, function(IList<uint>) had to be written function(IList&lt;uint&gt;)就我而言, function(IList<uint>)必须写成function(IList&lt;uint&gt;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM