Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在IntelliSense中隐藏某些泛型类型的扩展方法_C#_Extension Methods_Intellisense - Fatal编程技术网

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

C# 在IntelliSense中隐藏某些泛型类型的扩展方法,c#,extension-methods,intellisense,C#,Extension Methods,Intellisense,我有一个扩展方法: public static void Foo<T>(this MyClass<T> target) where T : IEnumerable { // Code goes here } 公共静态void Foo(此MyClass目标) 其中T:IEnumerable { //代码在这里 } 如果T是字符串,我想对Intelissense隐藏此扩展方法,但对于其他类型,我不想像处理字符串时隐藏Linq中IEnumerable的扩展方

我有一个扩展方法:

public static void Foo<T>(this MyClass<T> target)
    where T : IEnumerable
{
    // Code goes here
}
公共静态void Foo(此MyClass目标)
其中T:IEnumerable
{
//代码在这里
}
如果T是字符串,我想对Intelissense隐藏此扩展方法,但对于其他类型,我不想像处理字符串时隐藏Linq中IEnumerable的扩展方法那样隐藏此扩展方法。
我已经查看了
EditorBrowsableAttribute
,但它似乎不允许隐藏基于泛型类型的方法。

尝试将
EditorBrowsableAttribute
放置到此方法(也可能是包含此方法的类)并将该方法重新定位到另一个程序集(另一个项目)。然后,编译程序集并卸载项目,这样您就只有DLL引用了。这是使用
EditorBrowsableAttribute

功能的唯一方法我希望该方法在IntelliSense中可见,我只想在
T
string
EditorBrowsableAttribute
时它不可见,因为
string
清楚明确地实现了
IEnumerable
IEnumerable
这在语义上是不可能的。您对此无能为力。@Cornelius您唯一可以尝试的是创建重载,该重载将接受除
char
之外的所有您需要的类型,作为
t
for
IEnumerable