2013-05-15 34 views
3

根据此答案:“Should a property have the same name as its type?”,我已开始使用与其类名相同的属性名称。但最近我遇到了一个奇怪的角落案例,我不知道这是否只是我的问题以及如何解决问题。这里是重复的情况下的代码:当属性名称与类名称相同时,智能感知不能使用扩展方法

class R 
{ 
    public Test Test { get; private set; } 

    public R() 
    { 
     Test = new Test(); 

     // IntelliSense not working here: 
     // Test.Use(
    } 
} 

public class Test  
{ 

} 

public static class Extensions 
{ 
    public static void Use(this Test test, string msg) 
    { 
     Console.WriteLine(msg); 
    } 
} 

我使用VS2010和.NET Framework 4.0

下面是该问题的视频:http://www.youtube.com/watch?v=HgszAu_Pir0&feature=youtu.be

回答

1

你能尝试使用。这个时选择房产?
例如。 this.Test.use()..

+0

这有帮助,谢谢! (你将在24小时左右获奖) 有关这种奇怪行为的原因的想法吗? – astef

+0

好吧,这是因为intelisense不确定您是否指的是班级或财产,因此需要(这个)事情来陈述'嘿我指的是班级成员' –

+0

不,它知道我是指因为它在组合框中显示“使用”方法。 Class'Test'没有静态的'Use'方法。不显示'使用'方法参数的原因真的很奇怪。这可能是我想的错误。 – astef

相关问题