Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
programming4us
Windows 7

Advanced .NET Framework with VB 2010 : Coding Attributes - Applying Attributes

- Windows 10 Product Activation Keys Free 2019 (All Versions)
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
6/30/2011 3:08:02 PM
When applying attributes to your own types or members, you enclose the attribute name between angle brackets, as in the following example:
<Serializable()>
Public Class Person

End Class

In this case the Serializable attribute is parameterless (and in this case you can omit round parenthesis).

When you apply an attribute, your object is decorated with that attribute. Another common description utilized when applying attributes is that an object is marked. Referring to the previous example, you can say that the Person class is decorated with the Serializable attribute or that it is marked as Serializable as well. Attributes can receive arguments. The following example shows how to pass arguments to the CLSCompliant attribute:

<CLSCompliant(True)>
Public Class Person

End Class

Attributes arguments are separated by commas according to the number of arguments required. As explained when discussing custom attributes, optional parameters are also allowed. You apply multiple attributes separating them with commas or writing each attribute after the other one. Both the following modes are perfectly legal:

<Serializable()>
<CLSCompliant(True)>
Public Class Person

End Class

<Serializable(), CLSCompliant(True)>
Public Class Person

End Class

Implicit-Line Continuation

In the first code snippet notice how attributes no longer require the underscore character when written on multiple lines. This is one of the allowed scenarios for the implicitline continuation features in Visual Basic 2010.


Attributes can be applied to the following programming elements:

  • Classes

  • Structures

  • Methods (including constructors)

  • Fields

  • Properties

  • Interfaces

  • Delegates and events

  • Parameters and return values

  • Enumerations

Attributes are information that is stored in the assembly metadata. Figure 1 represents how such information is stored within the assembly, including type information and member information.

Figure 1. Attribute information stored in the assembly metadata.


Considering the representation shown in Figure 1, you may notice the description about assembly metadata. You can apply attributes at the assembly level, in the AssemblyInformation.vb file. Generally assembly level attributes are set at design time with the My Project window’s tabs . This means that each application property has a related assembly-level attribute. There is just one attribute named Assembly that requires the specification of nested attributes setting particular properties. For example, the following attributes’ specifications set the title, description, and company name properties for the application:

<Assembly: AssemblyTitle("CodingAttribute")>
<Assembly: AssemblyDescription("Demo for Chapter 48")>
<Assembly: AssemblyCompany("Alessandro Del Sole")>

In the preceding code, Assembly is the main attribute, whereas AssemblyTitle, AssemblyDescription, and AssemblyCompany are other attributes that are nested into the Assembly declaration. Examining AssemblyInfo.vb you can see available assembly-level attributes, and you discover how each attribute is related to an application property settable in My Project. Until now you saw how to apply existing attributes, but these special objects provide great flexibility over your object development and provide the ability to deeply enhance your types, especially if you create custom attributes, as you will better understand in next section.

Other -----------------
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Working with Background Pages and Borders
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Managing Pages and Page Setup
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Understanding Layers
- Installing Windows 7 (part 4) - Using Windows Update & Installing Windows Service Packs
- Installing Windows 7 (part 3) - Upgrading from Windows XP to Windows 7 & Supporting Multiple-Boot Options
- Installing Windows 7 (part 2) - Performing an Upgrade to Windows 7, Troubleshooting Installation Problems & Migrating Files and Settings
- Installing Windows 7 (part 1) - Performing a Clean Install of Windows 7
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Grouping Shapes
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Inserting Fields & Inserting Pictures
- Microsoft Visio 2010 : Adding Sophistication to Your Drawings - Using Shape Data
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
Celebrity Style, Fashion Trends, Beauty and Makeup Tips.
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server