.NET Attributes and Reflection “What a developer needs to know……” Dan Douglas Blog:

Slides:



Advertisements
Similar presentations
Master Pages, User Controls, Site Maps, Localization Svetlin Nakov Telerik Corporation
Advertisements

CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
Generating Data Access Assemblies with IronRuby Rob Rowe Blog: rob-rowe.blogspot.com.
OBJECT ORIENTED PROGRAMMING M Taimoor Khan
.NET IL Obfuscation Presented by: Sarath Chandra Dorbala.
The Type System1. 2.NET Type System The type system is the part of the CLR that defines all the types that programmers can use, and allows developers.
The Microsoft View: Module 1: Getting Started. Copyright Course 2559B, Introduction to Visual Basic®.NET Programming with Microsoft®.NET. Lecture 1 Microsoft.
Advanced Object-Oriented Programming Features
16/22/2015 2:54 PM6/22/2015 2:54 PM6/22/2015 2:54 PMObject-Oriented Development Concept originated with simulating objects and their interactions. Adapted.
T HE B ASICS O F S OFTWARE A RCHITECTURE F OR.NET D EVELOPERS Dan Douglas | Senior Software Developer/ Architect Blog:
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Tahir Nawaz Visual Programming C# Week 2. What is C#? C# (pronounced "C sharp") is an object- oriented language that is used to build applications for.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 18 Slide 1 Software Reuse 2.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
A Free sample background from © 2001 By Default!Slide 1.NET Overview BY: Pinkesh Desai.
© 2004 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill/Irwin Programming the Web Using ASP.Net Chapter 2: The ASP.Net Template Dave.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
1 Introduction to.NET Framework. 2.NETFramework Internet COM+ Orchestration Orchestration Windows.NET Enterprise ServersBuildingBlockServices Visual Studio.NET.
Introduction to .Net Framework
Chapter 15 – Inheritance, Virtual Functions, and Polymorphism
1 8/29/05CS360 Windows Programming Professor Shereen Khoja.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition
Understanding Code Compilation and Deployment Lesson 4.
Kalpesh Padia Reflection in.Net. OVERVIEW 9/19/
Reflection in.Net Siun-Wai Seow. Objective Explain.NET Reflection When to use it? How to use it? Topic is in the final exam.
ASSEMBLY. A SSEMBLY Assemblies are the fundamental units of applications in the.net framework An assembly can contain classes, structures, interfaces.
Virtual techdays INDIA │ Nov 2010 Developing Office Biz Application using WPF on Windows 7 Sarang Datye │ Sr. Consultant, Microsoft Sridhar Poduri.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
.NET Framework Danish Sami UG Lead.NetFoundry
New team member / new project for the team Helps analyze relationships and structure Understanding code Locates code in unfamiliar code bases Understand.
All types in the CLR are self-describing – CLR provides a reader and writer for type definitions System.Reflection & System.Reflection.emit – You can ‘read’
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Reflection Leveraging the Power of Metadata. Objectives Provide an introduction to.NET Reflection Explain how applications can use Reflection to explore.
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:
ABHISHEK BISWAS.NET Reflection Dynamically Create, Find and Invoke Types.
Rajiv and Shipra Introduction to.NET (asp.net,c#,vb)
Effective C# 50 Specific Way to Improve Your C# Item 42, 43.
Created By: Kevin Cherry. A library that creates a display to run on top of your game allowing you to retrieve/set values and invoke methods.
1 Hammad Khan. Agenda.NET Framework Introduction to Visual C#
Reflection.NET Support for Reflection. What is Reflection Reflection: the process by which a program can observe and modify its own structure and behavior.
1.
Presented by Vishy Grandhi.  Architecture (Week 1) ◦ Development Environments ◦ Model driven architecture ◦ Licensing and configuration  AOT (Week 2)
Attributes C#.Net Software Development Version 1.0.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Lecture Videos will no longer be posted. Assignment 3 is due Sunday, the 8 th, 7pm. Today: –System Design,
C# and.NET. .NET Architecture  Compiling and running code that targets.NET  Advantages of Microsoft Intermediate Language (MSIL)  Value and Reference.
Reflection Programming under the hood SoftUni Team Technical Trainers Software University
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.
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
INTRODUCTION BEGINNING C#. C# AND THE.NET RUNTIME AND LIBRARIES The C# compiler compiles and convert C# programs. NET Common Language Runtime (CLR) executes.
Chapter 7: Modifiability
INF230 Basics in C# Programming
/* LIFE RUNS ON CODE*/ Konstantinos Pantos Microsoft MVP ASP.NET
Reflection SoftUni Team Technical Trainers C# OOP Advanced
Reflection SoftUni Team Technical Trainers C# OOP Advanced
Advanced .NET Programming I 7th Lecture
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.
Present by Andie Saizan, MCP
.NET and .NET Core 10. Enabling Contracts Pan Wuming 2017.
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
Advanced .NET Programming I 8th Lecture
Computer Science II for Majors
Presentation transcript:

.NET Attributes and Reflection “What a developer needs to know……” Dan Douglas Blog: Presented By

What are Attributes? A.NET Object Represents data you want to associate with a target within the assembly Many possible targets, including, Assembly, Class, Member, Constructor, Enum, Interface, and Event Intrinsic Attributes (part of the CLR) Custom Attributes (developed)

…..Attributes Create a custom attribute by creating a class that inherits from System.Attribute Attributes are accessed by the application using reflection to get attribute information Useful to easily provide additional data to a target without having to write a lot of additional code

…..Attributes Multiple attributes can be assigned to a single target Many attributes in the System.ComponentModel namespace used by UI controls ◦ Provides information like Visibility, and Display Name

How to Specify an Attribute In this example the LastName Property is given the category of Main Info and the Display Name of Last Name UI Controls such as grids or the PropertyGrid use this information

What is Reflection? “In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior” (from Wikipedia) Application can read it’s own metadata Late-binding access to objects without knowing the information at design time ◦ Example: instantiate a class located outside the project by name or call a method of a class by name

Reflection Usage In.NET View metadata within an assembly Type Discovery ◦ Look at types within an assembly and also be able to instantiate them and use them Late Binding ◦ Dynamically instantiate types ◦ Invoke properties and methods dynamically from dynamically instantiated classes Create your own types and IL at runtime using Reflection.Emit (advanced)

From a Technical Perspective… Reflection objects are available in the System.Reflection namespace Some of the classes available in the reflection namespace: ◦ Assembly ◦ ConstructorInfo ◦ MethodInfo

From a Technical Perspective… Some of the classes available in the reflection namespace: ◦ EventInfo ◦ PropertyInfo ◦ ParameterInfo ◦ CustomAttributeData

From a Technical Perspective… System.Reflection.Emit Namespace ◦ Advanced Level of Reflection ◦ Used in Very Specialized Scenarios ◦ Dynamically build assemblies and types ◦ Allows you to generate and execute.NET (IL-Intermediate Language) code on demand at runtime

Red Gate.NET Reflector Useful utility that uses reflection to get information about.NET assemblies Allows you to view, navigate, and search through the class hierarchies of.NET assemblies Look at the code behind the objects in.NET Framework classes or any.NET compiled components to see how they work Because reflection allows access to private members, these members are visible within.NET reflector (Demo -.NET Reflector)

Many Practical Uses….. Pluggable Application Architectures ◦ At runtime, load modules such as UI components into the application Business Objects ◦ Revert\cancel changes to a business object by cycling through its properties using reflection Quick and Dirty User Interfaces ◦ Get properties of a business object and add appropriate labels/text boxes to a form at runtime using property names

Reflection Performance ◦ Reflection is faster in.NET 2.0 and higher than it was in.NET 1.1 ◦ When using reflection on a server (ex: ASP.NET) special concern should be taken to ensure that performance won’t be impacted with much higher workloads ◦ In situations where you do not know the object at design time, use a standard interface when possible  You can avoid further reflection calls once you have a reference to the object by calling the methods of the interface ◦ Don’t avoid reflection due to performance concerns – rather use it where it makes sense

Demo….. Use reflection to dynamically load an assembly located outside of the project and access and invoke one its methods

Resources Hanselminutes Podcast #37 – Reflection O’Reilly – Programming C# Chapter 18 (Attributes And Reflection) Dodge Common Performance Pitfalls to Craft Speedy Applications Real-world Reflection in.NET My Blog (Dan Douglas)

Questions? Consulting Inquiries? (519) Dan Douglas Blog: