CSE459_CSharp_Extra_Attributes

CSE459_CSharp_Extra_Attributes - Programming in C#...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Attributes l Many systems have a need to decorate code with additional information. l Traditional solutions l Add keywords or pragma’s to language l Use external files, e.g., .IDL, .DEF l C# solution: Attributes l Metadata – descriptive elements that decorate types and members (assembly, module, type, member, return value and parameter).
Background image of page 2
l Attributes are classes; they inherit from System.Attribute l Attach an attribute to a class, type, etc. Attributes - Example class HelpUrlAttribute : System.Attribute { public HelpUrlAttribute(string url) { … } } [HelpUrl(“http://SomeUrl/APIDocs/SomeClass”)] class SomeClass { … }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Attributes - Example l Attributes can be queried at runtime by reflection: Type type = typeof (MyClass); foreach ( object attr in type.GetCustomAttributes()) { if (attr is HelpUrlAttribute) { HelpUrlAttribute help = (HelpUrlAttribute) attr; myBrowser.Navigate(help.Url); } }
Background image of page 4
Uses of Attributes in .Net l Provide custom additions to metadata for managed types l Support serialization l Support debugging and tracing l Set COM+ attributes l
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 14

CSE459_CSharp_Extra_Attributes - Programming in C#...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online