Study your flashcards anywhere!

Download the official Cram app for free >

  • Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key

image

Play button

image

Play button

image

Progress

1/16

Click to flip

16 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)
What general kinds of attributes are there?
Predefined or custom.
What are the reserved attributes?
There are only two reserved attributes, Conditional and Obsolete.
Give an example of attribute usage, i.e., show a code snippet.
[Obsolete] public myClass { ... };

//This class should not be used.

or

[Conditional("Debug")] void DebugTrace() { ... }

Compile this method only if the Debug flag is defined.
What types of declarations can an attribute target?
Most declarations. A complete list can be found at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfattributetargets.asp
Can all attributes be used on all targets?
No. Most attributes must be attached to a specific language element. However, there are some global attributes.
To what elements do global attributes apply?
Assemblies or modules.
This is pretty high level stuff.
Name two global assembly attributes.
The following are found in the System.Reflection namespace.

AssemblyConfigurationAttribute
AssemblyCultureAttribute
AssemblyDescriptionAttribute
AssemblyKeyFileAttribute
AssemblyKeyNameAttribute
AssemblyDelaySignAttribute
AssemblyTitleAttribute
AssemblyVersionAttribute
What System.Reflection attributes are used with the strong name tool?
AssemblyKeyFileAttribute
AssemblyKeyNameAttribute
AssemblyDelaySignAttribute

Use the file name from the SN.exe (strong name utility) as arguments to these attributes.
How can you create your own custom attributes.
Create a class that inherits form the System.Attribute class.
It's a classy act.
Give a quick code example that builds a custom attribute
using System;
//restrict attribute usage to classes only
[AttributeUsage(AttributeTargets.Class)]
public class myClass(string astring)
{
//constructor
public Collector(string astring
{
this.astring = astring;
date = 1993;
}
//private versions of parameters
public short date;
string astring;
}
How is name space collision avoided when building attributes?
All attributes implicitly end with "Attribute". Thus "Collector" from the example will be treated as "CollectorAttribute" by the system.
The Attributes are implicitly obvious.
What System.Reflection method is used to retrieve attribute information from Attributes?
Either
public virtual object[] GetCustomAttributes(bool);
or
public static Attribute GetCustomAttribute(Assembly, Type);
What are the two types of parameters that are supported by Attribute Classes?
Positional Parameters:
a. Must be specified when the attribute is used.
b. Must be set by constructor.

Named Parameters:
a. optional
b. when specified name of parameter must be specified. i.e., foo = foovalue
c. named parameters are similar to properties. But defined at the class level.
Ya gotta do it or maybe you don't.
What types may an attribute argument be?
Simple numeric types including char.
string
System.Type
enums
object
one-dimensional arrays of any of the above types.
KISS
Where can you find the acceptable values for the AttributeTargets attribute?
AttributeTargets enumeration
Look in online help.
If you wanted to create a attribute that could be used more than once how would you do it?
[AttributeUsage(AttributeTargets.All,AllowMultiple = true)]
Note: AllowMultiple must be named.