المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Visual Studio doesn't detect invalid parameter type errors?



C# Programming
12-23-2009, 09:00 PM
I've been working with Visual Studio as hobbyist for a few years, but I only discovered this today. The way I found out was by moving some methods to another class. One of the methods used a Point class (of the System.Drawing namespace), but I didn't add a using-directive for that namespace. Then when I wanted to pass an instance of the Point class to that method from another class (which did have the directive to System.Drawing), it told me I was passing the wrong type.

That's when I discovered I forgot the using-directive to System.Drawing in the codefile of the method that also used the Point class. However, Visual Studio never warned me for that. Although the type I defined for that parameter was completely non-existing, it didn't mark it. Even if I said the parameter should be of type "sldhfsdf", which didn't exist at all (no directive to a potential namespace could have solved that), it still didn't mention anything, and acted as if it was an existing type. I could even use the parameter in the method, and it would propose it in the IntelliSense list.

Only I try to compile, it does return an error.

To clarify, here's an example that seems to be alright to Visual Studio's error checking.

public class Test
{
public void MyMethod(abcabc var1)
{
var1 = null;
}
}

While writing this piece of code, Visual Studio won't tell me this is wrong. The only way to find out is by compiling, or calling the method somewhere so it would tell me I'm either passing an unexisting or invalid variable.

Both Visual Studio 2008 and 2005 seem to do this. Could anyone explain me why this is the case?