This is a migrated thread and some comments may be shown as answers.

Just a thought ...

2 Answers 34 Views
Code Analysis
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 15 Jan 2010, 02:46 PM
I've just been looking at some code that I've inherited and had this ...
public partial class MyControl : System.Web.UI.UserControl 
    RadAjaxManager localManager; 
 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        localManager = RadAjaxManager.GetCurrent(Page); 
        ... 
    } 
     
    ... 
     
    void SomeMethod()  
    { 
        ... 
        RadAjaxManager localManager; 
        localManager = RadAjaxManager.GetCurrent(Page); 
        localManager.ResponseScripts.Add(...); 
    } 
 

Now, OK, it's perfectly legal but I can't imagine it is the sort of thing a professional developer would do on purpose, so I wonder if this kind of hiding an object with a wider scope is something we should expect JC to at least warn us about when it does happen.

As I say, just a Friday afternoon thought.

--
Stuart

2 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 19 Jan 2010, 08:41 AM
Hello Stuart,

That's a good idea. I have added to our product backlog list to show warnings as "Local variable VAR hides field FIELD" in such cases.

All the best,
Jordan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Stuart Hemming
Top achievements
Rank 2
answered on 19 Jan 2010, 08:45 AM
Cool.

I am a JustCode user and the warning "Local variable VAR hides field FIELD" was my idea. :-)

--
Stuart
Tags
Code Analysis
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Jordan
Telerik team
Stuart Hemming
Top achievements
Rank 2
Share this question
or