Me, Me, Me!!! Why does designer add all these me's?

  • Thread starter Thread starter Martin Ortiz
  • Start date Start date
M

Martin Ortiz

for example....VS.Net adds all these "Me" qualifiers.....in Initialization
code (this is just an example, my question is not specific to this)



Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection()

Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection()

Me.OleDbCommand1 = New System.Data.OleDb.OleDbCommand()

Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand()

Me.SqlConnection2 = New System.Data.SqlClient.SqlConnection()



My question, why the use of the qualifier "Me" all the time? Is this really
necessary? Would the code not work in some contexts without the "Me"
qualifier?
 
My question, why the use of the qualifier "Me" all the time? Is this
really
necessary? Would the code not work in some contexts without the "Me"
qualifier?

Hi, yes, because there maybe global variables (heaven forbid) in a module
with the same name as a component. Me explictally refers all the variables
to the class instance.

Also, there may be classes Imported at the top of your code that export
variables with the same name, and whatnot.

This is in rare cases of course, because I sincerely hope you are using
Option Strict, and you haven't got any global control variables declared ;-)

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
 
It is necessary, at least as it currently stands in .NET. It would take a
rewrite of the MS CodeDOM generator to change this behavior, or custom
behavior on a per language basis using snippets. Snippets, however, should
be avoided at all costs.

This is because the designer code is produced by the MS CodeDOM. If you
check out GDI+ Architect, our System.Drawing code designer, you'll see the
same sort of thing.

The reason it does this is, every generated field must be a field "of
something". In the case of member level declarations, the "something" is a
self reference - a CodeThisReferenceExpression to be specific. Adding this
reference forces the "Me" (this in C#) statement to emit. So every non
function or sub assignment, every assignment to a member, must be a member
of something.

Now as for the generated object instantiation statements (Me.blah = new
blah) - it does not have to be this way, but I can understand why it is. We
decided in GDI+ Architect to instantiate and declare at the same time.

For fun check this out:

http://msdn.microsoft.com/library/d.../cpgenref/html/cpconcodedomquickreference.asp
 
As a side note. I find myself including the me qualifiers in my own code.
It brings up the intellisense and saves time and typing.
 
you can also use <ALT> <Right Arrow> to bring that up without typing "me."



As a side note. I find myself including the me qualifiers in my own code.
It brings up the intellisense and saves time and typing.
 
Slonocode said:
As a side note. I find myself including the me qualifiers in my own
code. It brings up the intellisense and saves time and typing.

Right, me too, but I think the designer doesn't need intellisense. ;-)
 
Hi Martin,

I think that is an aspect from VB.net programmers, a lot of them are lazy.

It is like a spellchecker, when you did not know about it, you did not need
it, now you know it, you cannot without it.

(And that they are lazy prevent others from getting unreadable code, so I
see it as a benefit)

Cor
 
wierd, i always use ctrl+space


Daniel Bass said:
you can also use <ALT> <Right Arrow> to bring that up without typing "me."



As a side note. I find myself including the me qualifiers in my own code.
It brings up the intellisense and saves time and typing.
 
Back
Top