SlideShare a Scribd company logo
.NET Attributes and Reflection“What a developer needs to know……”Presented ByDan Douglas      Blog: http://dandouglas.wordpress.com   Twitter: @Dan_Douglas   E-mail: dan.douglas@gmail.com
What are Attributes?A .NET ObjectRepresents data you want to associate with a target within the assemblyMany possible targets, including, Assembly, Class, Member, Constructor, Enum, Interface, and Event  Intrinsic Attributes (part of the CLR)Custom Attributes (developed)
…..AttributesCreate a custom attribute by creating a class that inherits from System.AttributeAttributes are accessed by the application using reflection to get attribute informationUseful to easily provide additional data to a target without having to write a lot of additional code
…..AttributesMultiple attributes can be assigned to a single targetMany attributes in the System.ComponentModel namespace used by UI controlsProvides information like Visibility, and Display Name
How to Specify an AttributeIn 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 informationWhat 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 timeExample: instantiate a class located outside the project by name or call a method of a class by name
Reflection Usage In .NETView metadata within an assemblyType DiscoveryLook at types within an assembly and also be able to instantiate them and use themLate BindingDynamically instantiate typesInvoke properties and methods dynamically from dynamically instantiated classesCreate your own types and IL at runtime using Reflection.Emit (advanced)
From a Technical Perspective…Reflection objects are available in the System.Reflection namespaceSome of the classes available in the reflection namespace:AssemblyConstructorInfoMethodInfo
From a Technical Perspective…Some of the classes available in the reflection namespace:EventInfoPropertyInfoParameterInfoCustomAttributeData
From a Technical Perspective…System.Reflection.Emit NamespaceAdvanced Level of ReflectionUsed in Very Specialized ScenariosDynamically build assemblies and typesAllows you to generate and execute.NET (IL-Intermediate Language) code on demand at runtime
Red Gate .NET ReflectorUseful 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 workBecause reflection allows access to private members, these members are visible within .NET reflector(Demo - .NET Reflector)
Many Practical Uses…..Pluggable Application ArchitecturesAt runtime, load modules such as UI components into the applicationBusiness ObjectsRevert\cancel changes to a business object by cycling through its properties using reflectionQuick and Dirty User InterfacesGet properties of a business object and add appropriate labels/text boxes to a form at runtime using property names
Reflection PerformanceReflection 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 workloadsIn situations where you do not know the object at design time, use a standard interface when possibleYou can avoid  further reflection calls once you have a reference to the object by calling the methods of the interfaceDon’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
ResourcesHanselminutes Podcast #37 – Reflectionhttp://www.hanselminutes.com/default.aspx?showID=37O’Reilly – Programming C# Chapter 18 (Attributes And Reflection)http://oreilly.com/catalog/progcsharp/chapter/ch18.htmlDodge Common Performance Pitfalls to Craft Speedy Applicationshttp://msdn.microsoft.com/en-us/magazine/cc163759.aspxReal-world Reflection in .NEThttp://www.devx.com/dotnet/Article/31578/1954My Blog (Dan Douglas)http://dandouglas.wordpress.com
Questions?Dan Douglas      Blog: http://dandouglas.wordpress.com   Twitter: @Dan_Douglas   E-mail: dan.douglas@gmail.comConsulting Inquiries? (519) 777-2258

More Related Content

What's hot (20)

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
Amin Mesbahi
 
.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
Amin Mesbahi
 
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
Amin Mesbahi
 
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
Day3
madamewoolf
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
Siraj Memon
 
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
Amin Mesbahi
 
.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
Amin Mesbahi
 
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
Amin Mesbahi
 
BCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-IBCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-I
Vaibhavj1234
 
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
 
.NET and C# Introduction
.NET and C# Introduction.NET and C# Introduction
.NET and C# Introduction
Siraj Memon
 

Viewers also liked (20)

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
 
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
 
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
 
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
 
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
 
Ad

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
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
 
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
 
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
 
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
 
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
 
Ad

Recently uploaded (20)

Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME FlowProviding an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization ProgramOracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
“State-space Models vs. Transformers for Ultra-low-power Edge AI,” a Presenta...
Edge AI and Vision Alliance
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
Secure Access with Azure Active Directory
Secure Access with Azure Active DirectorySecure Access with Azure Active Directory
Secure Access with Azure Active Directory
VICTOR MAESTRE RAMIREZ
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Ben Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding WorldBen Blair - Operating Safely in a Vibe Coding World
Ben Blair - Operating Safely in a Vibe Coding World
AWS Chicago
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
“Solving Tomorrow’s AI Problems Today with Cadence’s Newest Processor,” a Pre...
Edge AI and Vision Alliance
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 

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

  • 1. .NET Attributes and Reflection“What a developer needs to know……”Presented ByDan Douglas    Blog: http://dandouglas.wordpress.com Twitter: @Dan_Douglas E-mail: [email protected]
  • 2. What are Attributes?A .NET ObjectRepresents data you want to associate with a target within the assemblyMany possible targets, including, Assembly, Class, Member, Constructor, Enum, Interface, and Event Intrinsic Attributes (part of the CLR)Custom Attributes (developed)
  • 3. …..AttributesCreate a custom attribute by creating a class that inherits from System.AttributeAttributes are accessed by the application using reflection to get attribute informationUseful to easily provide additional data to a target without having to write a lot of additional code
  • 4. …..AttributesMultiple attributes can be assigned to a single targetMany attributes in the System.ComponentModel namespace used by UI controlsProvides information like Visibility, and Display Name
  • 5. How to Specify an AttributeIn this example the LastName Property is given the category of Main Info and the Display Name of Last Name
  • 6. UI Controls such as grids or the PropertyGrid use this informationWhat 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 timeExample: instantiate a class located outside the project by name or call a method of a class by name
  • 7. Reflection Usage In .NETView metadata within an assemblyType DiscoveryLook at types within an assembly and also be able to instantiate them and use themLate BindingDynamically instantiate typesInvoke properties and methods dynamically from dynamically instantiated classesCreate your own types and IL at runtime using Reflection.Emit (advanced)
  • 8. From a Technical Perspective…Reflection objects are available in the System.Reflection namespaceSome of the classes available in the reflection namespace:AssemblyConstructorInfoMethodInfo
  • 9. From a Technical Perspective…Some of the classes available in the reflection namespace:EventInfoPropertyInfoParameterInfoCustomAttributeData
  • 10. From a Technical Perspective…System.Reflection.Emit NamespaceAdvanced Level of ReflectionUsed in Very Specialized ScenariosDynamically build assemblies and typesAllows you to generate and execute.NET (IL-Intermediate Language) code on demand at runtime
  • 11. Red Gate .NET ReflectorUseful 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 workBecause reflection allows access to private members, these members are visible within .NET reflector(Demo - .NET Reflector)
  • 12. Many Practical Uses…..Pluggable Application ArchitecturesAt runtime, load modules such as UI components into the applicationBusiness ObjectsRevert\cancel changes to a business object by cycling through its properties using reflectionQuick and Dirty User InterfacesGet properties of a business object and add appropriate labels/text boxes to a form at runtime using property names
  • 13. Reflection PerformanceReflection 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 workloadsIn situations where you do not know the object at design time, use a standard interface when possibleYou can avoid further reflection calls once you have a reference to the object by calling the methods of the interfaceDon’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. ResourcesHanselminutes Podcast #37 – Reflectionhttp://www.hanselminutes.com/default.aspx?showID=37O’Reilly – Programming C# Chapter 18 (Attributes And Reflection)http://oreilly.com/catalog/progcsharp/chapter/ch18.htmlDodge Common Performance Pitfalls to Craft Speedy Applicationshttp://msdn.microsoft.com/en-us/magazine/cc163759.aspxReal-world Reflection in .NEThttp://www.devx.com/dotnet/Article/31578/1954My Blog (Dan Douglas)http://dandouglas.wordpress.com
  • 16. Questions?Dan Douglas    Blog: http://dandouglas.wordpress.com Twitter: @Dan_Douglas E-mail: [email protected] Inquiries? (519) 777-2258

Editor's Notes

  • #3: Custom Attributes are created by the developer to be used for his or her own purpose or requirements
  • #4: 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
  • #5: Metadata - - info about the data about the types, code, assembly
  • #6: -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
  • #7: Metadata - - info about the data about the types, code, assembly
  • #8: Metadata - - info about the data about the types, code, assembly
  • #9: 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)
  • #10: CustomAttributeData – used for getting access to custom attribute information from Classes, Properties, Methods, etc
  • #11: 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.
  • #13: |Quick and Dirty User Interfaces – could be expanded by using custom attributes that specify size, read-only, color, label name, etc
  • #14: 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.