简体   繁体   English

隐藏IntelliSense中某些泛型类型的扩展方法

[英]Hiding extension methods for certain generic types in IntelliSense

I have an extension method: 我有一个扩展方法:

public static void Foo<T>(this MyClass<T> target)
    where T : IEnumerable
{
    // Code goes here
}

I want to hide this extension method from InteliSense if T is a string but not for other types in the same way that the Extension methods for IEnumerable in Linq is hidden when you are working with a string. 我希望隐藏InteliSense中的这个扩展方法,如果T是一个字符串,但不是其他类型,就像使用字符串时隐藏Linq中IEnumerable的扩展方法一样。 I have looked at the EditorBrowsableAttribute but it does not seem to allow hiding a method based on the generic type. 我查看了EditorBrowsableAttribute但它似乎不允许隐藏基于泛型类型的方法。

Try placing the EditorBrowsableAttribute to this method (and maybe to the class that containts this method, too) and relocate the method to another assembly (another project). 尝试将EditorBrowsableAttribute放置到此方法(也可能放到包含此方法的类)并将方法重定位到另一个程序集(另一个项目)。 After that, compile the assembly and unload the project, so you would have only the DLL reference. 之后,编译程序集并卸载项目,因此您将只有DLL引用。 This is the only way to use the power of EditorBrowsableAttribute . 这是使用EditorBrowsableAttribute的唯一方法。

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

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