Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.

Slides:



Advertisements
Similar presentations
JSP and Servelets.
Advertisements

Using.NET Platform Note: Most of the material of these slides have been taken & extended from Nakov’s excellent overview for.NET framework, MSDN and wikipedia.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
AP 08/01 Component Programming with C# and.NET 1st Class Component Support Robust and Versionable Creating and using attributes API integration –DLL import.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
C# Language Design Peter Hallam Software Design Engineer C# Compiler Microsoft Corporation.
IEG3080 Tutorial 11 Prepared by Ryan. Outline Enterprise Application Architecture Layering Structure Domain Logic C# Attribute Aspect Oriented Programming.
Reflection, Conversions, and Exceptions Tom Roeder CS fa.
C# vs. C++ What's Different & What's New. An example C# public sometype myfn { get; set; } C++ public: sometype myfn { sometype get (); void set (sometype.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
February 24 th -25 th 2004 Daragh Byrne – EPCC Additional.NET Concepts.
1 Introduction to.NET Framework. 2.NETFramework Internet COM+ Orchestration Orchestration Windows.NET Enterprise ServersBuildingBlockServices Visual Studio.NET.
Programming Languages and Paradigms Object-Oriented Programming.
Java Beans.
.NET Framework Introduction: Metadata
The Metadata System1. 2 Introduction Metadata is data that describes data. Traditionally, metadata has been found in language- specific files (e.g. C/C++
CIS NET Applications1 Chapter 2 –.NET Component- Oriented Programming Essentials.
.NET Framework & C#.
Other Types in OOP Enumerations, Structures, Generic Classes, Attributes Svetlin Nakov Technical Trainer Software University
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
Stimulsoft Reports.Net 20 Problems which Stimulsoft Reports.Net solves
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Reflection in.Net Siun-Wai Seow. Objective Explain.NET Reflection When to use it? How to use it? Topic is in the final exam.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Managed C++. Objectives Overview to Visual C++.NET Concepts and architecture Developing with Managed Extensions for C++ Use cases Managed C++, Visual.
© FPT Software Advanced features in C# 1. © FPT Software Agenda Attributes Delegates & Events Anonymous Types & Dynamic Type Extension Methods Lambda.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Component Programming with C# and.NET. C# components The most commonly used components in.NET are the visual controls that you add to Windows Forms such.
E FFECTIVE C# 50 Specific Ways to Improve Your C# Second Edition Bill Wagner محمد حسین سلطانی.
tom perkins1 XML Web Services -.NET FRAMEWORK – Part 1 CHAPTER 1.1 – 1.3.
ASP.NET State Management. Slide 2 Lecture Overview Client state management options Cookies Server state management options Application state Session state.
What’s new in Kentico CMS 5.0 Michal Neuwirth Product Manager Kentico Software.
MD – Object Model Domain eSales Checker Presentation Régis Elling 26 th October 2005.
PI Data Archive Server COM Points Richard Beeson.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
Module 1: Getting Started. Introduction to.NET and the.NET Framework Exploring Visual Studio.NET Creating a Windows Application Project Overview Use Visual.
Programming in Java CSCI-2220 Object Oriented Programming.
Introduction to Java Beans CIS 421 Web-based Java Programming.
Module 14: Attributes. Overview Overview of Attributes Defining Custom Attributes Retrieving Attribute Values.
Attributes C#.Net Software Development Version 1.0.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
.NET Mobile Application Development XML Web Services.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Building Custom Controls with ASP.NET and the Microsoft ®.NET Framework Rames Gantanant Microsoft Regional Director, Thailand
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Reflection and Attributes.
.Net Reflection Taipan Tamsare. Overview Reflection core concepts Exploring metadata Detail information Attributes Building Types at runtime.
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
METADATA IN.NET Presented By Sukumar Manduva. INTRODUCTION  What is Metadata ? Metadata is a binary information which contains the complete description.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 7 th Lecture Pavel Ježek
Module 4: Troubleshooting Web Servers. Overview Use IIS 7.0 troubleshooting features to gather troubleshooting information Use the Runtime Control and.
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Browne Bag Seminar Applied .Net Attributes
Using Application Domains Effectively
Programming in C# Properties
Out-of-Process Components
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Module 1: Getting Started
Introduction to C# AKEEL AHMED.
Programming in C# Comparison (Sorting)
.NET and .NET Core 10. Enabling Contracts Pan Wuming 2017.
Module 10: Implementing Managed Code in the Database
How to organize and document your classes
Out-of-Process Components
CIS 199 Final Review.
Jim Fawcett CSE775 – Distributed Objects Spring 2006
Creating and Using Classes
Presentation transcript:

Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis

Attributes Many systems have a need to decorate code with additional information. Traditional solutions Add keywords or pragma’s to language Use external files, e.g.,.IDL,.DEF C# solution: Attributes Metadata – descriptive elements that decorate types and members (assembly, module, type, member, return value and parameter).

Attributes are classes; they inherit from System.Attribute Attach an attribute to a class, type, etc. Attributes - Example class HelpUrlAttribute : System.Attribute { public HelpUrlAttribute(string url) { … } … } [HelpUrl(“ class SomeClass { … }

Attributes - Example 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); }

Uses of Attributes in.Net Provide custom additions to metadata for managed types Support serialization Support debugging and tracing Set COM+ attributes Activation, queuing, security, events, contexts, object pooling, synchronization, transactions Support creation of COM objects Support creation of.Net controls Support creation of Web Services Create ATL Server code – essentially builds ISAPI filters Implement performance counters Implement OLEDB consumers

Kinds of Attributes Custom attributes Add entries to metadata but are not used by run-time Distinguished custom attributes These attributes have data stored in the assembly next to the items to which it applies. OneWay is a distinguished custom attribute that affects marshaling by the run-time Pseudo custom attributes Changes, does not extend existing metadata Serializable is a pseudo custom attribute. It sets or resets the metadata flag tdSerializable

Defining Custom Attributes Create a class marked with the AttributeUsage attribute [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] class myAttribute : System.Attribute { … } Targets include: Assembly, Class, Delegate, Event, Field, Method, …, All The attribute class provides a constructor some state, and properties to retrieve the state. The state is stored in the metadata of the assembly that implements the attributed target. It is retrieved using the Reflection API.

Attributes are classes; they inherit from System.Attribute Attach an attribute to a class, type, etc. Attributes - Example class HelpUrlAttribute : System.Attribute { public HelpUrlAttribute(string url) { … } … } [HelpUrl(“ class SomeClass { … } Note, it is allowed and customary to remove the Attribute suffix from the type name.

Provided Attributes in.Net [CLSCompliant(true)]- class fails to compile if not compliant [Conditional(“Debug”)]- won’t get called unless Debug defined [Assembly: AssemblyTitle(“…”)]- assembly descriptions [Assembly: AssemblyVersion(“1.2”)] [DllImport(“kernel32.dll”)]- accessing unmanaged global function public static extern int Beep(int freq, int dur); [Serializable()]- enabling serialization public class myClass { … } [OneWay()]- marshal only to remote object public void myFunc(string msg) { … } [Synchronization()]- allow access by one thread at a time class SomeClass : ContextBoundObject { … } [Obsolete()]- generates a compiler error when used

Design-Time and Security Attributes Attributes used with user defined controls [Category(“Custom Properties”)]- makes property page category [DefaultEvent(myEvent)]- double click on control to wire up [Description(“myPropertDesc”)]- description shown when selected [ToolBoxBitmap(“myBitMap.bmp”)] – defines bitmap used in toolbox Declarative security settings [FileIOPermission(SecurityAction.Deny, public in ReadFile(string path) { … }

Preprocessor Directives C# provides preprocessor directives that serve a number of functions Unlike C++, there is not a separate preprocessor The “preprocessor” name is preserved only for consistency with C++ Some C++ preprocessor features removed: #include : Not needed Macro version of #define : removed for clarity

Preprocessor Directives

#define Debug public class Debug { [Conditional("Debug")] public static void Assert(bool condition, String msg) { if (!condition) { throw new AssertionException(msg); } void DoSomething() {... // If Debug is not defined, the next line is // not even called Assert((x == y), “X should equal Y”);... } Conditional Compilation

Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis