Sub definition

  • Thread starter Thread starter Sanjay Kulkarni
  • Start date Start date
S

Sanjay Kulkarni

What is the meaning of the expression includes within <> before the
definition of a sub?

eg

<some expression> Public Sub nameOfSub()

- Sanjay Kulkarni.
 
Sanjay said:
What is the meaning of the expression includes within <> before the
definition of a sub?

eg

<some expression> Public Sub nameOfSub()

- Sanjay Kulkarni.

Open up Visual Studio, click on Sub, then press F1.

You will be presented with a help page displaying (depending on the
version of VS you're using) something like:

[ <attrlist> ] [{ Overloads | Overrides | Overridable |
NotOverridable | MustOverride | Shadows | Shared }]
[{ Public | Protected | Friend | Protected Friend | Private }]
Sub name [(arglist)] [ Implements interface.definedname ]
[ statements ]
[ Exit Sub ]
[ statements ]
End Sub

or

[ <attributelist> ] [Partial] [ accessmodifier ] [ proceduremodifiers ]
[ Shared ] [ Shadows ]
Sub name [ (Of typeparamlist) ] [ (parameterlist) ] [ Implements
implementslist | Handles eventlist ]
[ statements ]
[ Exit Sub ]
[ statements ]
End Sub


I hope that helps.
 
Sanjay Kulkarni said:
What is the meaning of the expression includes within <> before the
definition of a sub?

eg

<some expression> Public Sub nameOfSub()

It's called attribute. The VB documentation contains more information on
attributes. All the attributes defined in the .NET Framework are described
there too (just place the caret on the attribute and press the F1 key).
 
The are markers that delinate a compiler "attribute", which is basically a
special instruction just for the compiler. They are a way to mark, not only
a Sub (you can use them on almost all class members), with extra information
that the compiler needs to know.

-Scott
 
The are markers that delinate a compiler "attribute", which is basically a
special instruction just for the compiler. They are a way to mark, not only
a Sub (you can use them on almost all class members), with extra information
that the compiler needs to know.

-Scott

Hmmm.. While there are some attributes that affect compile time behavior (for
example, ObsoleteAttribute) - most attributes are processed at runtime. They
are markers that can be used by other classes to gain additional information
about the class, property, or method. For instance, the attributes that you
can place on the properties of a class to influence the behavior of the
PropertyGrid.

One place I use them is for mapping object properties to fields in a dataset
at runtime - sort of a simplified ORM tool.
 
I refer to them as compiler attributes because the compiler turns them into
assembly metadata to then use as necessary.

http://ondotnet.com/pub/a/dotnet/excerpt/vbnut_8/index1.html

-Scott

Ok... that's true. They are put into the metadata of the assembly - but, I was
mostly refering to your remarks about them being special instructions for
the compiler.

There are very few attributes that are recognized to have meaning to the
compiler - beyond informing it to store the metadata. It seems a little
unclear to describe a mostly runtime concept this way - at least it did to me,
hence my comments :)
 
But, technically, they are all instructions for the compiler. They tell the
compiler to store this metadata about the type.

I get what you are saying as far as what the attribute actually does for/to
the type, but it is the compiler that creates this metadata in the first
place.

-Scott
 
Sure, but:
x = 1
is an instruction to the compiler to generate some IL. By your
definition, how is that different from what an attribute does, except
that one affects metadata and the other IL.

But, technically, they are all instructions for the compiler. They tell the
compiler to store this metadata about the type.

I get what you are saying as far as what the attribute actually does for/to
the type, but it is the compiler that creates this metadata in the first
place.

-Scott
 
Well sure, but attributes are a *different* way to talk to the compiler.
Saying x =1 is using the main programming language. Attributes do not.

From the article I referenced earlier:

"You may wonder why attributes are used on the .NET platform and why they
are not simply implemented as language elements. The answer comes from the
fact that attributes are stored as metadata in an assembly, rather than as
part of its executable code. As an item of metadata, the attribute describes
the program element to which it applies and is available through reflection
both at design time (if a graphical environment such as Visual Studio .NET
is used), at compile time (when the compiler can use it to modify,
customize, or extend the compiler's basic operation), and at runtime (when
it can be used by the Common Language Runtime or by other executable code to
modify the code's ordinary runtime behavior)."

-Scott


Jack Jackson said:
Sure, but:
x = 1
is an instruction to the compiler to generate some IL. By your
definition, how is that different from what an attribute does, except
that one affects metadata and the other IL.
 
Back
Top