简体   繁体   中英

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. I have looked at the EditorBrowsableAttribute but it does not seem to allow hiding a method based on the generic type.

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). After that, compile the assembly and unload the project, so you would have only the DLL reference. This is the only way to use the power of EditorBrowsableAttribute .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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