Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  

AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml


Attributes

C sharp

+ Font mai mare | - Font mai mic




DOCUMENTE SIMILARE

Trimite pe Messenger
Attributes - Attribute classes
Primary expressions - Postfix increment and decrement operators
Declarations
Namespace declarations
The using statement
Unsafe code - Unsafe contexts
Constant expressions
Enums - declarations, Enums members
Exceptions - Causes of exceptions
Default values


Attributes

C# is an imperative language, but like all imperative languages it does have some declarative elements. For example, the accessibility of a method in a class is specified by decorating it public, protected, internal, protected internal, or private. Through its support for attributes, C# generalizes this capability, so that programmers can invent new kinds of declarative information, attach this declarative information to various program entities, and retrieve this declarative information at run-time. Programs specify this additional declarative information by defining and using attributes.




For instance, a framework might define a HelpAttribute attribute that can be placed on program elements such as classes and methods, enabling developers to provide a mapping from program elements to documentation for them. The example

using System;

[AttributeUsage(AttributeTargets.All)]
public class HelpAttribute: Attribute

     public string Topic = null;

     private string url;

     public string Url
     }
}

defines an attribute class named HelpAttribute, or Help for short, that has one positional parameter (string url) and one named argument (string Topic). Positional parameters are defined by the formal parameters for public instance constructors of the attribute class, and named parameters are defined by public non-static read-write fields and properties of the attribute class.



The example

[Help('https://www.microsoft.com//Class1.htm')]
public class Class1

}

shows several uses of the attribute.

Attribute information for a given program element can be retrieved at run-time by using reflection support. The example

using System;

class Test
, Topic = ', ha.Url, ha.Topic);
           }
     }
}

checks to see if Class1 has a Help attribute, and writes out the associated Topic and Url values if the attribute is present.






Politica de confidentialitate



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 763
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2021 . All rights reserved

Distribuie URL

Adauga cod HTML in site