SlideShare a Scribd company logo
.NET Attributes and Reflection “What a developer needs to know……” Presented By Dan Douglas      Blog: http://dandouglas.wordpress.com   Twitter: @Dan_Douglas   E-mail: dan.douglas@gmail.com
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 ,[object Object]
UI Controls such as grids or the PropertyGrid use this information,[object Object]
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 Revertancel 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 – Reflectionhttp://www.hanselminutes.com/default.aspx?showID=37 O’Reilly – Programming C# Chapter 18 (Attributes And Reflection)http://oreilly.com/catalog/progcsharp/chapter/ch18.html Dodge Common Performance Pitfalls to Craft Speedy Applicationshttp://msdn.microsoft.com/en-us/magazine/cc163759.aspx Real-world Reflection in .NEThttp://www.devx.com/dotnet/Article/31578/1954 My Blog (Dan Douglas) http://dandouglas.wordpress.com
Questions? Dan Douglas      Blog: http://dandouglas.wordpress.com   Twitter: @Dan_Douglas   E-mail: dan.douglas@gmail.com Consulting Inquiries? (519) 777-2258

More Related Content

What's hot

C# Unit5 Notes
C# Unit5 NotesC# Unit5 Notes
C# Unit5 Notes
Sudarshan Dhondaley
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
Palak Sanghani
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9
aminmesbahi
 
.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17
aminmesbahi
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
Lushanthan Sivaneasharajah
 
Java RMI
Java RMIJava RMI
Java RMI
Ankit Desai
 
Java chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsJava chapter 3 - OOPs concepts
Java chapter 3 - OOPs concepts
Mukesh Tekwani
 
Building maintainable web apps with Angular MS TechDays 2017
Building maintainable web apps with Angular MS TechDays 2017Building maintainable web apps with Angular MS TechDays 2017
Building maintainable web apps with Angular MS TechDays 2017
Erik van Appeldoorn
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
Richie Rump
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5
aminmesbahi
 
Understanding Annotations in Java
Understanding Annotations in JavaUnderstanding Annotations in Java
Understanding Annotations in Java
Ecommerce Solution Provider SysIQ
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
yogita kachve
 
dot NET Framework
dot NET Frameworkdot NET Framework
dot NET Framework
Roy Antony Arnold G
 
BCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-IBCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-I
Vaibhavj1234
 
Java annotations
Java annotationsJava annotations
Java annotations
FAROOK Samath
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database First
Jibran Rasheed Khan
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
Doncho Minkov
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
Sanjaya Prakash Pradhan
 
Day3
Day3Day3
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
Siraj Memon
 

What's hot (20)

C# Unit5 Notes
C# Unit5 NotesC# Unit5 Notes
C# Unit5 Notes
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
 
.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9.NET Core, ASP.NET Core Course, Session 9
.NET Core, ASP.NET Core Course, Session 9
 
.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 
Java RMI
Java RMIJava RMI
Java RMI
 
Java chapter 3 - OOPs concepts
Java chapter 3 - OOPs conceptsJava chapter 3 - OOPs concepts
Java chapter 3 - OOPs concepts
 
Building maintainable web apps with Angular MS TechDays 2017
Building maintainable web apps with Angular MS TechDays 2017Building maintainable web apps with Angular MS TechDays 2017
Building maintainable web apps with Angular MS TechDays 2017
 
Entity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic UnicornsEntity Framework: Code First and Magic Unicorns
Entity Framework: Code First and Magic Unicorns
 
.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5.NET Core, ASP.NET Core Course, Session 5
.NET Core, ASP.NET Core Course, Session 5
 
Understanding Annotations in Java
Understanding Annotations in JavaUnderstanding Annotations in Java
Understanding Annotations in Java
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
 
dot NET Framework
dot NET Frameworkdot NET Framework
dot NET Framework
 
BCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-IBCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-I
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Learn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database FirstLearn Entity Framework in a day with Code First, Model First and Database First
Learn Entity Framework in a day with Code First, Model First and Database First
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
C#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developersC#.net interview questions for dynamics 365 ce crm developers
C#.net interview questions for dynamics 365 ce crm developers
 
Day3
Day3Day3
Day3
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
 

Viewers also liked

Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
Rohit Vipin Mathews
 
.NET Reflection
.NET Reflection.NET Reflection
.NET Reflection
Robert MacLean
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
Pooja Gaikwad
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
LearnNowOnline
 
Reflection power pointpresentation ppt
Reflection power pointpresentation pptReflection power pointpresentation ppt
Reflection power pointpresentation ppt
Rohit Vipin Mathews
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
BlackRabbitCoder
 
Net remoting
Net remotingNet remoting
Net remoting
Vidhi Patel
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
Niit Care
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+Reflection
Mohammad Shaker
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
AkashThakrar
 
Session 6
Session 6Session 6
Session 6
LiquidHub
 
Net remoting
Net remotingNet remoting
Net remoting
eduardojunior78
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#
Wekoslav Stefanovski
 
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Fons Sonnemans
 
Day02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTDay02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDT
Nguyen Patrick
 
.Net Core
.Net Core.Net Core
.Net Core
Bertrand Le Roy
 
ASP.NET Core 1.0 Overview
ASP.NET Core 1.0 OverviewASP.NET Core 1.0 Overview
ASP.NET Core 1.0 Overview
Shahed Chowdhuri
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
Jm Ramos
 
Session#1 csharp MTCS
Session#1 csharp MTCSSession#1 csharp MTCS
Session#1 csharp MTCS
Ahmad Ehab
 

Viewers also liked (20)

Reflection in C#
Reflection in C#Reflection in C#
Reflection in C#
 
.NET Reflection
.NET Reflection.NET Reflection
.NET Reflection
 
Learning .NET Attributes
Learning .NET AttributesLearning .NET Attributes
Learning .NET Attributes
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
Reflection power pointpresentation ppt
Reflection power pointpresentation pptReflection power pointpresentation ppt
Reflection power pointpresentation ppt
 
C#/.NET Little Wonders
C#/.NET Little WondersC#/.NET Little Wonders
C#/.NET Little Wonders
 
Net remoting
Net remotingNet remoting
Net remoting
 
13 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_1913 iec t1_s1_oo_ps_session_19
13 iec t1_s1_oo_ps_session_19
 
Study research in April
Study research in AprilStudy research in April
Study research in April
 
CSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+ReflectionCSharp Advanced L05-Attributes+Reflection
CSharp Advanced L05-Attributes+Reflection
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
Session 6
Session 6Session 6
Session 6
 
Net remoting
Net remotingNet remoting
Net remoting
 
Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#Smoke and Mirrors - Reflection in C#
Smoke and Mirrors - Reflection in C#
 
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#Building & Designing Windows 10 Universal Windows Apps using XAML and C#
Building & Designing Windows 10 Universal Windows Apps using XAML and C#
 
Day02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDTDay02 01 Advance Feature in C# DH TDT
Day02 01 Advance Feature in C# DH TDT
 
.Net Core
.Net Core.Net Core
.Net Core
 
ASP.NET Core 1.0 Overview
ASP.NET Core 1.0 OverviewASP.NET Core 1.0 Overview
ASP.NET Core 1.0 Overview
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Session#1 csharp MTCS
Session#1 csharp MTCSSession#1 csharp MTCS
Session#1 csharp MTCS
 

Similar to .NET Attributes and Reflection - What a Developer Needs to Know...

Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
Greg Sohl
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.ppt
TemesgenAzezew
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
cummings49
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
FALLEE31188
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
Rafael Coutinho
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
Reflection Slides by Zubair Dar
Reflection Slides by Zubair DarReflection Slides by Zubair Dar
Reflection Slides by Zubair Dar
zubairdar6
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
Alfresco Software
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
Jason Townsend, MBA
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
Gary Pedretti
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
Adikhan27
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
Saurabh Narula
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
VRE Cancer Imaging BL RIC Workshop 22032011
VRE Cancer Imaging BL RIC Workshop 22032011VRE Cancer Imaging BL RIC Workshop 22032011
VRE Cancer Imaging BL RIC Workshop 22032011
djmichael156
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
LenchoMamudeBaro
 
Design patterns
Design patternsDesign patterns
Design patterns
Binu Bhasuran
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
dn
 
.NET Framework Projet with C#
.NET Framework Projet with C#.NET Framework Projet with C#
.NET Framework Projet with C#
eclumson
 
C# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech TalkC# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech Talk
Michael Heydt
 
20.1 creating functions_part_20.1
20.1 creating functions_part_20.120.1 creating functions_part_20.1
20.1 creating functions_part_20.1
Oracle HRMS Functional Consultant
 

Similar to .NET Attributes and Reflection - What a Developer Needs to Know... (20)

Object Oriented Programming In .Net
Object Oriented Programming In .NetObject Oriented Programming In .Net
Object Oriented Programming In .Net
 
chapter 5 Objectdesign.ppt
chapter 5 Objectdesign.pptchapter 5 Objectdesign.ppt
chapter 5 Objectdesign.ppt
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Reflection Slides by Zubair Dar
Reflection Slides by Zubair DarReflection Slides by Zubair Dar
Reflection Slides by Zubair Dar
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Object-oriented programming 3.pptx
Object-oriented programming 3.pptxObject-oriented programming 3.pptx
Object-oriented programming 3.pptx
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
VRE Cancer Imaging BL RIC Workshop 22032011
VRE Cancer Imaging BL RIC Workshop 22032011VRE Cancer Imaging BL RIC Workshop 22032011
VRE Cancer Imaging BL RIC Workshop 22032011
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
.NET Framework Projet with C#
.NET Framework Projet with C#.NET Framework Projet with C#
.NET Framework Projet with C#
 
C# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech TalkC# 3.0 and LINQ Tech Talk
C# 3.0 and LINQ Tech Talk
 
20.1 creating functions_part_20.1
20.1 creating functions_part_20.120.1 creating functions_part_20.1
20.1 creating functions_part_20.1
 

Recently uploaded

AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Neo4j
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
DianaGray10
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
Neo4j
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
Fwdays
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 

Recently uploaded (20)

AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid ResearchHarnessing the Power of NLP and Knowledge Graphs for Opioid Research
Harnessing the Power of NLP and Knowledge Graphs for Opioid Research
 
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectorsConnector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
Connector Corner: Seamlessly power UiPath Apps, GenAI with prebuilt connectors
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge GraphGraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
GraphRAG for LifeSciences Hands-On with the Clinical Knowledge Graph
 
"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota"Choosing proper type of scaling", Olena Syrota
"Choosing proper type of scaling", Olena Syrota
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 

.NET Attributes and Reflection - What a Developer Needs to Know...

  • 1. .NET Attributes and Reflection “What a developer needs to know……” Presented By Dan Douglas    Blog: http://dandouglas.wordpress.com Twitter: @Dan_Douglas E-mail: dan.douglas@gmail.com
  • 2. 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)
  • 3. …..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
  • 4. …..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
  • 5.
  • 6.
  • 7. 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)
  • 8. 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
  • 9. From a Technical Perspective… Some of the classes available in the reflection namespace: EventInfo PropertyInfo ParameterInfo CustomAttributeData
  • 10. 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
  • 11. 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)
  • 12. Many Practical Uses….. Pluggable Application Architectures At runtime, load modules such as UI components into the application Business Objects Revertancel 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
  • 13. 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
  • 14. Demo….. Use reflection to dynamically load an assembly located outside of the project and access and invoke one its methods
  • 15. Resources Hanselminutes Podcast #37 – Reflectionhttp://www.hanselminutes.com/default.aspx?showID=37 O’Reilly – Programming C# Chapter 18 (Attributes And Reflection)http://oreilly.com/catalog/progcsharp/chapter/ch18.html Dodge Common Performance Pitfalls to Craft Speedy Applicationshttp://msdn.microsoft.com/en-us/magazine/cc163759.aspx Real-world Reflection in .NEThttp://www.devx.com/dotnet/Article/31578/1954 My Blog (Dan Douglas) http://dandouglas.wordpress.com
  • 16. Questions? Dan Douglas    Blog: http://dandouglas.wordpress.com Twitter: @Dan_Douglas E-mail: dan.douglas@gmail.com Consulting Inquiries? (519) 777-2258

Editor's Notes

  1. Custom Attributes are created by the developer to be used for his or her own purpose or requirements
  2. Reflection – we will talk about that in the upcoming slidesUseful to easily provide additional data to a target without having to write a lot of additional code-Example: An attribute that specifies what a Display or Friendly Name should be for a field or a Tooltip – this functionality can be added to the property of the class simply by using a custom attribute
  3. Metadata - - info about the data about the types, code, assembly
  4. -The PropertyGrid uses the information to group Properties by Category and also use a friendly display name-3rd Part Grid controls typically use Display Name to display a friendly column name
  5. Metadata - - info about the data about the types, code, assembly
  6. Metadata - - info about the data about the types, code, assembly
  7. Assembly Load assemblies at runtime Locate the types used within the assemblyConstructorInfo Discover attributes of a class constructor Access to constructor metadata Invoke a ConstructorMethodInfoDiscover attributes of a method Access to method metadata Invoke a method (late binding)
  8. CustomAttributeData – used for getting access to custom attribute information from Classes, Properties, Methods, etc
  9. Microsoft Intermediate LanguageSome primary uses include Script Engines and CompilersThis can have a speed increase in certain scenarios – for example when doing a lot of looping within a calculation could have a speed increase if you generate IL code of the entire calculation and then just do the calculation.. No looping. Only recommended in very advanced and specialized scenarios.
  10. |Quick and Dirty User Interfaces – could be expanded by using custom attributes that specify size, read-only, color, label name, etc
  11. Think about how you use reflection because there is a performance hitASP.NET – There may not be a performance impact using reflection with just a few users, but it may have a largely magnified impact with higher workloads…Example: If you know the interface of the type of object you are instantiating using reflection (because you don’t know the name of the object until runtime) you can eliminate further reflection calls by casting the new instance of the Interface to an object declared of that interface type. Method calls to interface methods will not require a reflection call because you know the methods of the Interface.Don’t avoid reflection due to performance concerns – rather use it where it makes sense  Even the .NET Framework uses Reflection internally in the framework.