{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE459_CSharp_Extra_Attributes

CSE459_CSharp_Extra_Attributes - Programming in C...

Info icon This 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
Image of page 1

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

View Full Document Right 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).
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 { … }
Image of page 3

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

View Full Document Right 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); } }
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 Activation, queuing, security, events, contexts, object pooling,
Image of page 5

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern