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
forIEnumerable
。