SlideShare a Scribd company logo
Learn about .NET Attributes
July 26, 2016.net training institute, Computer Training .net certification in pune, .net classes, .net courses, .net courses
in pune, .net jobs, .net technology, .net training, .net training institute pune, ASP.net courses
Assemblies are the building blocks of .NET Framework ; they form the basic unit of deployment, reuse, version control,
reuse, activation scoping and security permissions. An assembly is a collection of types and resources that are created to
work together and form a functional and logical unit.
.NET assemblies are self-describing, i.e. information about an assembly is stored in the assembly itself. This
information is called Meta data. .NET also allows you to put additional information in the meta data via Attributes.
Attributes are used in many places within the .NET framework.
This page discusses what attributes are, how to use inbuilt attributes and how to customize attributes.
Define .NET Attributes
A .NET attribute is information that can be attached with a class, an assembly, property, method and other members. An
attribute bestows to the metadata about an entity that is under consideration. An attribute is actually a class that is either
inbuilt or can be customized. Once created, an attribute can be applied to various targets including the ones mentioned
above.
For better understanding, let’s take this example:
[WebService]public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
5. public string HelloWorld()
{
return “Hello World”;
}
}
The above code depicts a class named WebService1 that contains a method: HelloWorld(). Take note of the class and
method declaration. The WebService1 class is decorated with [WebService] and HelloWorld() is decorated with
[WebMethod].
Both of them – [WebService] and [WebMethod] – are features. The [WebService] attribute indicates that the target of
the feature (WebService1 class) is a web service. Similarly, the [WebMethod] feature indicates that the target under
consideration (HelloWorld() method) is a web called method. We are not going much into details of these specific
attributes, it is sufficient to know that they are inbuilt and bestow to the metadata of the respective entities.
Two broad ways of classification of attributes are : inbuilt and custom. The inbuilt features are given by .NET
framework and are readily usable when required. Custom attributes are developer created classes.
On observing a newly created project in Visual Studio, you will find a file named AssemblyInfo.cs. This file constitute
attributes that are applicable to the entire project assembly.
For instance, consider the following AssemblyInfo.cs from an ASP.NET Web Application
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.[assembly: AssemblyTitle("CustomAttributeDemo")][assembly:
AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomAttributeDemo")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the ‘*’ as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
As you can see there are many attributes such as AssemblyTitle, AssemblyDescription and AssemblyVersion. Since
their target is the hidden assembly, they use [assembly: <attribute_name>] syntax.
Information about the features can be obtained through reflection. Most of the inbuilt attributes are handled by .NET
framework internally but for custom features you may need to create a mechanism to observe the metadata emitted by
them.
Inbuilt Attributes
In this section you will use Data Annotation Attributes to prove model data. Nees to start by creating a new ASP.NET
MVC Web Application. Then add a class to the Models folder and name it as Customer. The Customer class contains
two public properties and is shown below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
5. using System.ComponentModel.DataAnnotations;
namespace CustomAttributesMVCDemo.Models
{
public class Customer
10. {
[Required]
public string CustomerID { get; set; }
[Required]
15. [StringLength(20,MinimumLength=5,ErrorMessage="Invalid company name!")]
public string CompanyName { get; set; }
}
}
Take note of the above code. The Customer class comprise of two string properties – CustomerID and CompanyName.
Its important to note that these properties are decorated with data annotation features residing in the
System.ComponentModel.DataAnnotations namespace.
The [Required] features points that the CustomerID property must be given some value in order to consider it to be a
valid model. Similarly, the CompanyName property is designed with [Required] and [StringLength] attributes. The
[StringLength] feature is used to specify that the CompanyName should be a at least five characters long and at max
twenty characters long. An error message is also specified in case the value given to the CompanyName property
doesn’t meet the criteria. To note that [Required] and [StringLength] attributes are actually classes – RequiredAttribute
and StringLengthAttribute – defined in the System.ComponentModel.DataAnnotations namespace.
Now, add the HomeController class to the Controllers folder and write the following action methods:
public ActionResult Index()
{
return View();
}
5.
public ActionResult ProcessForm()
{
Customer obj = new Customer();
bool flag = TryUpdateModel(obj);
10. if(flag)
{
ViewBag.Message = “Customer data received successfully!”;
}
else
15. {
ViewBag.Message = “Customer data validation failed!”;
}
return View(“Index”);
}
The Index() action method simply returns the Index view. The Index.cshtml consists of a simple <form> as given
below:
<form action=”/home/processform” method=”post”>
<span>Customer ID : </span>
<input type=”text” name=”customerid” />
<span>Company Name : </span>
5. <input type=”text” name=”companyname” />
<input type=”submit” value=”Submit”/>
</form>
<strong>@ViewBag.Message</strong>
<strong>@Html.ValidationSummary()</strong>
The values entered in the customer ID text box and company name text box are submitted to the ProcessForm() action
method.
The ProcesssForm() action method uses TryUpdateModel() method to allot the characteristics of the Customer model
with the form field values. The TryUpdateModel() method returns true if the model properties contain proven data as
per the condition given by the data annotation features, otherwise it returns false. The model errors are displayed on the
page using ValidationSummary() Html helper.
Then run the application and try submitting the form without entering Company Name value. The following figure
shows how the error message is shown:
Thus data notation attributes are used by ASP.NET MVC to do model validations.
Creating Custom Attributes
In the above example, some inbuilt attributes were used. This section will teach you to create a custom attribute and
then apply it. For the sake of this example let’s assume that you have developed a class library that has some complex
business processing. You want that this class library should be consumed by only those applications that got a valid
license key given by you. You can devise a simple technique to accomplish this task.
Let’s begin by creating a new class library project. Name the project LicenseKeyAttributeLib. Modify the default class
from the class library to resemble the following code:
namespace LicenseKeyAttributeLib
{
[AttributeUsage(AttributeTargets.All)]
public class MyLicenseAttribute:Attribute
5. { public string Key { get; set; }
}
}
As you can see the MyLicenseAttribute class is created by taking it from the Attribute base class is provided by the
.NET framework. By convention all the attribute classes end with “Attribute”. But while using these attributes you don’t
need to write “Attribute”.
Thus MyLicenseAttribute class will be used as [MyLicense] on the target.
The MyLicenseAttribute class contains just one property – Key – that represents a license key.
The MyLicenseAttribute itself is decorated with an inbuilt attribute – [AttributeUsage]. The [AttributeUsage] feature is
used to set the target for the custom attribute being created.
Now, add another class library to the same solution and name it ComplexClassLib. The ComplexClassLib represents the
class library doing some complex task and consists of a class as shown below:
public class ComplexClass1
{
public string ComplexMethodRequiringKey()
{
5. //some code goes here
return “Hello World!”;
}
}
The ComplexMethodRequiringKey() method of the ComplexClass1 is supposed to be doing some complex operation.
Applying Custom Attributes
Next need to add an ASP.NET Web Forms Application to the same solution.
Then use the ComplexMethodRequiringKey() inside the Page_Load event handler:
protected void Page_Load(object sender, EventArgs e)
{
ComplexClassLib.ComplexClass1 obj = new ComplexClassLib.ComplexClass1();
Label1.Text = obj.ComplexMethodRequiringKey();
}
The return value from ComplexMethodRequiringKey() is assigned to a Label control.
Now it’s time to use the MyLicenseAttribute class that was created earlier. Open the AssemblyInfo.cs file from the web
application and add the following code to it:
using System.Reflection;
…
using LicenseKeyAttributeLib;
5. …
[assembly: MyLicense(Key = "4fe29aba")]
The AssemblyInfo.cs file now uses MyLicense custom attribute to specify a license key. Notice that although the
attribute class name is MyLicenseAttribute, while using the attribute you just mention it as MyLicense.
Summary
Attributes help you to add metadata to their target. The .NET framework though provides several inbuilt attributes ,
there are chances to customize a few more. You knew to use inbuilt data notation features to validate model data; create
a custom attribute and used it to design an assembly. A custom feature is a class usually derived from the Attribute base
class and members can be added to the custom attribute class just like you can do for any other class.
If you are considering to take ASP.Net training then our CRB Tech .Net Training center would be very helpful in
fulfilling your aspirations. We update ourself with the ongoing generation so you can learn ASP.Net with us.
Stay connected to this page of CRB Tech reviews for more technical up-gradation and other resources.
For more information on dot net do visit : http://crbtech.in/Dot-Net-Training

More Related Content

What's hot

TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4
Lokesh Singrol
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
People Strategists
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
Lokesh Singrol
 
TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6
Lokesh Singrol
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
Divyam Pateriya
 
Advance Java Practical file
Advance Java Practical fileAdvance Java Practical file
Advance Java Practical file
varun arora
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkAkhil Mittal
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
Naga Muruga
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
Lokesh Singrol
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
Collaboration Technologies
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
kamal kotecha
 
Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
Sunil kumar Mohanty
 

What's hot (20)

TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4TY.BSc.IT Java QB U4
TY.BSc.IT Java QB U4
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Hibernate III
Hibernate IIIHibernate III
Hibernate III
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
 
Mvc acchitecture
Mvc acchitectureMvc acchitecture
Mvc acchitecture
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
 
TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
Advance Java Practical file
Advance Java Practical fileAdvance Java Practical file
Advance Java Practical file
 
JSP Technology I
JSP Technology IJSP Technology I
JSP Technology I
 
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity FrameworkRepository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
 
Hibernate I
Hibernate IHibernate I
Hibernate I
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 
Oracle application-development-framework-best-practices
Oracle application-development-framework-best-practicesOracle application-development-framework-best-practices
Oracle application-development-framework-best-practices
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
 
Synopsis
SynopsisSynopsis
Synopsis
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
The most basic inline tag
The most basic inline tagThe most basic inline tag
The most basic inline tag
 
Java Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and ExampleJava Hibernate Programming with Architecture Diagram and Example
Java Hibernate Programming with Architecture Diagram and Example
 
Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
 

Viewers also liked

Guia eletricista-residencial completo
Guia eletricista-residencial completoGuia eletricista-residencial completo
Guia eletricista-residencial completo
henfor
 
Guia 3 rocio jimenez
Guia 3 rocio jimenezGuia 3 rocio jimenez
Guia 3 rocio jimenezjanethrocio
 
1438596470-79546591
1438596470-795465911438596470-79546591
1438596470-79546591Tracy Gorgen
 
Documento word copia seguridad ymacros
Documento word   copia seguridad ymacrosDocumento word   copia seguridad ymacros
Documento word copia seguridad ymacros15309292
 
La religión
La religión La religión
La religión
EylinBanda
 
Normas de etiqueta en internet
Normas de etiqueta en internetNormas de etiqueta en internet
Normas de etiqueta en internet
Deiby Chaparro
 
Omar shanticv
Omar shanticvOmar shanticv
Omar shanticv
Omar Shanti
 
Ecuela del zulia
Ecuela del zuliaEcuela del zulia
Ecuela del zulia
Placido Gutierrez
 
20160419155427374_0002
20160419155427374_000220160419155427374_0002
20160419155427374_0002Jackquine Saal
 
e l e
  e   l   e  e   l   e
Cefalometria dr. huete 006
Cefalometria     dr. huete 006Cefalometria     dr. huete 006
Cefalometria dr. huete 006Rigoberto Huete
 
Nota bb visanet imprensa (1)
Nota bb visanet imprensa (1)Nota bb visanet imprensa (1)
Nota bb visanet imprensa (1)Miguel Rosario
 
Zend Expressive in 15 Minutes
Zend Expressive in 15 MinutesZend Expressive in 15 Minutes
Zend Expressive in 15 Minutes
Chris Tankersley
 
TECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADO
TECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADOTECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADO
TECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADO
JILAN C. GERAL
 
David Stack's Top 4 Entrepreneur Reads of 2016
David Stack's Top 4 Entrepreneur Reads of 2016David Stack's Top 4 Entrepreneur Reads of 2016
David Stack's Top 4 Entrepreneur Reads of 2016
David Stack
 

Viewers also liked (20)

Guia eletricista-residencial completo
Guia eletricista-residencial completoGuia eletricista-residencial completo
Guia eletricista-residencial completo
 
Guia 3 rocio jimenez
Guia 3 rocio jimenezGuia 3 rocio jimenez
Guia 3 rocio jimenez
 
1438596470-79546591
1438596470-795465911438596470-79546591
1438596470-79546591
 
Documento word copia seguridad ymacros
Documento word   copia seguridad ymacrosDocumento word   copia seguridad ymacros
Documento word copia seguridad ymacros
 
La religión
La religión La religión
La religión
 
Normas de etiqueta en internet
Normas de etiqueta en internetNormas de etiqueta en internet
Normas de etiqueta en internet
 
Actividad 1°. pascual
Actividad 1°. pascualActividad 1°. pascual
Actividad 1°. pascual
 
Tercera guia
Tercera guiaTercera guia
Tercera guia
 
GF Label
GF LabelGF Label
GF Label
 
Omar shanticv
Omar shanticvOmar shanticv
Omar shanticv
 
201604181621
201604181621201604181621
201604181621
 
Ecuela del zulia
Ecuela del zuliaEcuela del zulia
Ecuela del zulia
 
20160419155427374_0002
20160419155427374_000220160419155427374_0002
20160419155427374_0002
 
e l e
  e   l   e  e   l   e
e l e
 
Cefalometria dr. huete 006
Cefalometria     dr. huete 006Cefalometria     dr. huete 006
Cefalometria dr. huete 006
 
Nota bb visanet imprensa (1)
Nota bb visanet imprensa (1)Nota bb visanet imprensa (1)
Nota bb visanet imprensa (1)
 
presentaciòn de vida
presentaciòn de vidapresentaciòn de vida
presentaciòn de vida
 
Zend Expressive in 15 Minutes
Zend Expressive in 15 MinutesZend Expressive in 15 Minutes
Zend Expressive in 15 Minutes
 
TECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADO
TECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADOTECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADO
TECNOLOGIA DA INFORMAÇÃO NO MUNDO GLOBALIZADO
 
David Stack's Top 4 Entrepreneur Reads of 2016
David Stack's Top 4 Entrepreneur Reads of 2016David Stack's Top 4 Entrepreneur Reads of 2016
David Stack's Top 4 Entrepreneur Reads of 2016
 

Similar to Learn about dot net attributes

Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
Pooja Gaikwad
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
sonia merchant
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Sony Suci
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligeti
Naveen Kumar Veligeti
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
icubesystem
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER:  Programming sql server data miningMS SQL SERVER:  Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
sqlserver content
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data miningMS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
DataminingTools Inc
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfoliocummings49
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
vrluckyin
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
Suzanne Simmons
 
Architecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolArchitecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolAdriaan Venter
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
Ali Shah
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
Lee Englestone
 

Similar to Learn about dot net attributes (20)

Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Learn dot net attributes
Learn dot net attributesLearn dot net attributes
Learn dot net attributes
 
ASP.NET MVC3 RAD
ASP.NET MVC3 RADASP.NET MVC3 RAD
ASP.NET MVC3 RAD
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) kerenTutorial mvc (pelajari ini jika ingin tahu mvc) keren
Tutorial mvc (pelajari ini jika ingin tahu mvc) keren
 
CAD Report
CAD ReportCAD Report
CAD Report
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
Why use .net by naveen kumar veligeti
Why use .net by naveen kumar veligetiWhy use .net by naveen kumar veligeti
Why use .net by naveen kumar veligeti
 
Asp.net mvc training
Asp.net mvc trainingAsp.net mvc training
Asp.net mvc training
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER:  Programming sql server data miningMS SQL SERVER:  Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data miningMS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
Asp.NET MVC
Asp.NET MVCAsp.NET MVC
Asp.NET MVC
 
ASP.NET Identity
ASP.NET IdentityASP.NET Identity
ASP.NET Identity
 
Struts N E W
Struts N E WStruts N E W
Struts N E W
 
Architecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling ToolArchitecture Specification - Visual Modeling Tool
Architecture Specification - Visual Modeling Tool
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
 

More from sonia merchant

What does dot net hold for 2016?
What does dot net hold for 2016?What does dot net hold for 2016?
What does dot net hold for 2016?
sonia merchant
 
What does .net hold for 2016?
What does .net hold for 2016?What does .net hold for 2016?
What does .net hold for 2016?
sonia merchant
 
Data protection api's in asp dot net
Data protection api's in asp dot netData protection api's in asp dot net
Data protection api's in asp dot net
sonia merchant
 
Authorization p iv
Authorization p ivAuthorization p iv
Authorization p iv
sonia merchant
 
Authorization iii
Authorization iiiAuthorization iii
Authorization iii
sonia merchant
 
Authorization in asp dot net part 2
Authorization in asp dot net part 2Authorization in asp dot net part 2
Authorization in asp dot net part 2
sonia merchant
 
Asp dot-net core problems and fixes
Asp dot-net core problems and fixes Asp dot-net core problems and fixes
Asp dot-net core problems and fixes
sonia merchant
 
Search page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-netSearch page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-net
sonia merchant
 
Build a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-netBuild a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-net
sonia merchant
 
How to optimize asp dot-net application
How to optimize asp dot-net applicationHow to optimize asp dot-net application
How to optimize asp dot-net application
sonia merchant
 
How to optimize asp dot net application ?
How to optimize asp dot net application ?How to optimize asp dot net application ?
How to optimize asp dot net application ?
sonia merchant
 
10 things to remember
10 things to remember10 things to remember
10 things to remember
sonia merchant
 
Owin and-katana-overview
Owin and-katana-overviewOwin and-katana-overview
Owin and-katana-overview
sonia merchant
 
Top 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answersTop 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answers
sonia merchant
 
Next generation asp.net v next
Next generation asp.net v nextNext generation asp.net v next
Next generation asp.net v next
sonia merchant
 
Dot net universal apps
Dot net universal appsDot net universal apps
Dot net universal apps
sonia merchant
 
Browser frame building with c# and vb dot net
Browser frame building  with c# and vb dot netBrowser frame building  with c# and vb dot net
Browser frame building with c# and vb dot net
sonia merchant
 
A simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-frameworkA simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-framework
sonia merchant
 
Silverlight versions-features
Silverlight versions-featuresSilverlight versions-features
Silverlight versions-features
sonia merchant
 
History of silverlight versions and its features
History of silverlight versions and its featuresHistory of silverlight versions and its features
History of silverlight versions and its features
sonia merchant
 

More from sonia merchant (20)

What does dot net hold for 2016?
What does dot net hold for 2016?What does dot net hold for 2016?
What does dot net hold for 2016?
 
What does .net hold for 2016?
What does .net hold for 2016?What does .net hold for 2016?
What does .net hold for 2016?
 
Data protection api's in asp dot net
Data protection api's in asp dot netData protection api's in asp dot net
Data protection api's in asp dot net
 
Authorization p iv
Authorization p ivAuthorization p iv
Authorization p iv
 
Authorization iii
Authorization iiiAuthorization iii
Authorization iii
 
Authorization in asp dot net part 2
Authorization in asp dot net part 2Authorization in asp dot net part 2
Authorization in asp dot net part 2
 
Asp dot-net core problems and fixes
Asp dot-net core problems and fixes Asp dot-net core problems and fixes
Asp dot-net core problems and fixes
 
Search page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-netSearch page-with-elasticsearch-and-dot-net
Search page-with-elasticsearch-and-dot-net
 
Build a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-netBuild a-search-page-with-elastic search-and-dot-net
Build a-search-page-with-elastic search-and-dot-net
 
How to optimize asp dot-net application
How to optimize asp dot-net applicationHow to optimize asp dot-net application
How to optimize asp dot-net application
 
How to optimize asp dot net application ?
How to optimize asp dot net application ?How to optimize asp dot net application ?
How to optimize asp dot net application ?
 
10 things to remember
10 things to remember10 things to remember
10 things to remember
 
Owin and-katana-overview
Owin and-katana-overviewOwin and-katana-overview
Owin and-katana-overview
 
Top 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answersTop 15-asp-dot-net-interview-questions-and-answers
Top 15-asp-dot-net-interview-questions-and-answers
 
Next generation asp.net v next
Next generation asp.net v nextNext generation asp.net v next
Next generation asp.net v next
 
Dot net universal apps
Dot net universal appsDot net universal apps
Dot net universal apps
 
Browser frame building with c# and vb dot net
Browser frame building  with c# and vb dot netBrowser frame building  with c# and vb dot net
Browser frame building with c# and vb dot net
 
A simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-frameworkA simplest-way-to-reconstruct-.net-framework
A simplest-way-to-reconstruct-.net-framework
 
Silverlight versions-features
Silverlight versions-featuresSilverlight versions-features
Silverlight versions-features
 
History of silverlight versions and its features
History of silverlight versions and its featuresHistory of silverlight versions and its features
History of silverlight versions and its features
 

Recently uploaded

Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

Learn about dot net attributes

  • 1. Learn about .NET Attributes July 26, 2016.net training institute, Computer Training .net certification in pune, .net classes, .net courses, .net courses in pune, .net jobs, .net technology, .net training, .net training institute pune, ASP.net courses Assemblies are the building blocks of .NET Framework ; they form the basic unit of deployment, reuse, version control, reuse, activation scoping and security permissions. An assembly is a collection of types and resources that are created to work together and form a functional and logical unit. .NET assemblies are self-describing, i.e. information about an assembly is stored in the assembly itself. This information is called Meta data. .NET also allows you to put additional information in the meta data via Attributes. Attributes are used in many places within the .NET framework. This page discusses what attributes are, how to use inbuilt attributes and how to customize attributes. Define .NET Attributes A .NET attribute is information that can be attached with a class, an assembly, property, method and other members. An attribute bestows to the metadata about an entity that is under consideration. An attribute is actually a class that is either inbuilt or can be customized. Once created, an attribute can be applied to various targets including the ones mentioned above. For better understanding, let’s take this example: [WebService]public class WebService1 : System.Web.Services.WebService { [WebMethod]
  • 2. 5. public string HelloWorld() { return “Hello World”; } } The above code depicts a class named WebService1 that contains a method: HelloWorld(). Take note of the class and method declaration. The WebService1 class is decorated with [WebService] and HelloWorld() is decorated with [WebMethod]. Both of them – [WebService] and [WebMethod] – are features. The [WebService] attribute indicates that the target of the feature (WebService1 class) is a web service. Similarly, the [WebMethod] feature indicates that the target under consideration (HelloWorld() method) is a web called method. We are not going much into details of these specific attributes, it is sufficient to know that they are inbuilt and bestow to the metadata of the respective entities. Two broad ways of classification of attributes are : inbuilt and custom. The inbuilt features are given by .NET framework and are readily usable when required. Custom attributes are developer created classes. On observing a newly created project in Visual Studio, you will find a file named AssemblyInfo.cs. This file constitute attributes that are applicable to the entire project assembly. For instance, consider the following AssemblyInfo.cs from an ASP.NET Web Application // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly.[assembly: AssemblyTitle("CustomAttributeDemo")][assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("CustomAttributeDemo")] [assembly: AssemblyCopyright("Copyright © 2014")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number
  • 3. // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the ‘*’ as shown below: [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] As you can see there are many attributes such as AssemblyTitle, AssemblyDescription and AssemblyVersion. Since their target is the hidden assembly, they use [assembly: <attribute_name>] syntax. Information about the features can be obtained through reflection. Most of the inbuilt attributes are handled by .NET framework internally but for custom features you may need to create a mechanism to observe the metadata emitted by them. Inbuilt Attributes In this section you will use Data Annotation Attributes to prove model data. Nees to start by creating a new ASP.NET MVC Web Application. Then add a class to the Models folder and name it as Customer. The Customer class contains two public properties and is shown below: using System; using System.Collections.Generic; using System.Linq; using System.Web; 5. using System.ComponentModel.DataAnnotations; namespace CustomAttributesMVCDemo.Models { public class Customer 10. { [Required] public string CustomerID { get; set; } [Required] 15. [StringLength(20,MinimumLength=5,ErrorMessage="Invalid company name!")] public string CompanyName { get; set; } } }
  • 4. Take note of the above code. The Customer class comprise of two string properties – CustomerID and CompanyName. Its important to note that these properties are decorated with data annotation features residing in the System.ComponentModel.DataAnnotations namespace. The [Required] features points that the CustomerID property must be given some value in order to consider it to be a valid model. Similarly, the CompanyName property is designed with [Required] and [StringLength] attributes. The [StringLength] feature is used to specify that the CompanyName should be a at least five characters long and at max twenty characters long. An error message is also specified in case the value given to the CompanyName property doesn’t meet the criteria. To note that [Required] and [StringLength] attributes are actually classes – RequiredAttribute and StringLengthAttribute – defined in the System.ComponentModel.DataAnnotations namespace. Now, add the HomeController class to the Controllers folder and write the following action methods: public ActionResult Index() { return View(); } 5. public ActionResult ProcessForm() { Customer obj = new Customer(); bool flag = TryUpdateModel(obj); 10. if(flag) { ViewBag.Message = “Customer data received successfully!”; } else 15. { ViewBag.Message = “Customer data validation failed!”; } return View(“Index”); } The Index() action method simply returns the Index view. The Index.cshtml consists of a simple <form> as given below: <form action=”/home/processform” method=”post”> <span>Customer ID : </span>
  • 5. <input type=”text” name=”customerid” /> <span>Company Name : </span> 5. <input type=”text” name=”companyname” /> <input type=”submit” value=”Submit”/> </form> <strong>@ViewBag.Message</strong> <strong>@Html.ValidationSummary()</strong> The values entered in the customer ID text box and company name text box are submitted to the ProcessForm() action method. The ProcesssForm() action method uses TryUpdateModel() method to allot the characteristics of the Customer model with the form field values. The TryUpdateModel() method returns true if the model properties contain proven data as per the condition given by the data annotation features, otherwise it returns false. The model errors are displayed on the page using ValidationSummary() Html helper. Then run the application and try submitting the form without entering Company Name value. The following figure shows how the error message is shown: Thus data notation attributes are used by ASP.NET MVC to do model validations. Creating Custom Attributes In the above example, some inbuilt attributes were used. This section will teach you to create a custom attribute and then apply it. For the sake of this example let’s assume that you have developed a class library that has some complex business processing. You want that this class library should be consumed by only those applications that got a valid license key given by you. You can devise a simple technique to accomplish this task. Let’s begin by creating a new class library project. Name the project LicenseKeyAttributeLib. Modify the default class from the class library to resemble the following code: namespace LicenseKeyAttributeLib { [AttributeUsage(AttributeTargets.All)] public class MyLicenseAttribute:Attribute 5. { public string Key { get; set; } } }
  • 6. As you can see the MyLicenseAttribute class is created by taking it from the Attribute base class is provided by the .NET framework. By convention all the attribute classes end with “Attribute”. But while using these attributes you don’t need to write “Attribute”. Thus MyLicenseAttribute class will be used as [MyLicense] on the target. The MyLicenseAttribute class contains just one property – Key – that represents a license key. The MyLicenseAttribute itself is decorated with an inbuilt attribute – [AttributeUsage]. The [AttributeUsage] feature is used to set the target for the custom attribute being created. Now, add another class library to the same solution and name it ComplexClassLib. The ComplexClassLib represents the class library doing some complex task and consists of a class as shown below: public class ComplexClass1 { public string ComplexMethodRequiringKey() { 5. //some code goes here return “Hello World!”; } } The ComplexMethodRequiringKey() method of the ComplexClass1 is supposed to be doing some complex operation. Applying Custom Attributes Next need to add an ASP.NET Web Forms Application to the same solution. Then use the ComplexMethodRequiringKey() inside the Page_Load event handler: protected void Page_Load(object sender, EventArgs e) { ComplexClassLib.ComplexClass1 obj = new ComplexClassLib.ComplexClass1(); Label1.Text = obj.ComplexMethodRequiringKey(); }
  • 7. The return value from ComplexMethodRequiringKey() is assigned to a Label control. Now it’s time to use the MyLicenseAttribute class that was created earlier. Open the AssemblyInfo.cs file from the web application and add the following code to it: using System.Reflection; … using LicenseKeyAttributeLib; 5. … [assembly: MyLicense(Key = "4fe29aba")] The AssemblyInfo.cs file now uses MyLicense custom attribute to specify a license key. Notice that although the attribute class name is MyLicenseAttribute, while using the attribute you just mention it as MyLicense. Summary Attributes help you to add metadata to their target. The .NET framework though provides several inbuilt attributes , there are chances to customize a few more. You knew to use inbuilt data notation features to validate model data; create a custom attribute and used it to design an assembly. A custom feature is a class usually derived from the Attribute base class and members can be added to the custom attribute class just like you can do for any other class. If you are considering to take ASP.Net training then our CRB Tech .Net Training center would be very helpful in fulfilling your aspirations. We update ourself with the ongoing generation so you can learn ASP.Net with us. Stay connected to this page of CRB Tech reviews for more technical up-gradation and other resources. For more information on dot net do visit : http://crbtech.in/Dot-Net-Training