introduction to xaml with wpfjeremybytes.com/downloads/slides-practicalreflection.pdf ·...
TRANSCRIPT
![Page 1: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/1.jpg)
Practical Reflection
Presented by Jeremy Clarkwww.jeremybytes.com
![Page 2: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/2.jpg)
Just for Experts?
![Page 3: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/3.jpg)
Goal
@jeremybytes
![Page 4: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/4.jpg)
What is Reflection?
What is an assembly?
What is metadata?
How is the code compiled?
@jeremybytes
Inspecting the metadata and code in an assembly.
![Page 5: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/5.jpg)
.NET Assemblies
@jeremybytes
AssemblyManifest
Metadata+ IL
Resources(optional)
![Page 6: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/6.jpg)
Type Definitions
@jeremybytes
![Page 7: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/7.jpg)
Assembly Information
@jeremybytes
![Page 8: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/8.jpg)
Referenced Assemblies
@jeremybytes
![Page 9: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/9.jpg)
IL (Intermediate Language)
@jeremybytes
![Page 10: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/10.jpg)
Feature Overview
@jeremybytes
Activator
Type Assembly
ILGenerator
•
•
•
•
•
•
•
•
•
•
••
![Page 11: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/11.jpg)
Things You Can Do
@jeremybytes
![Page 12: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/12.jpg)
Things You Can Do
@jeremybytes
![Page 13: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/13.jpg)
Things You Can Do
@jeremybytes
![Page 14: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/14.jpg)
Encapsulation
@jeremybytes
Input
Output
![Page 15: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/15.jpg)
DEMO
Performance Concerns
![Page 16: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/16.jpg)
Best Practice
@jeremybytes
![Page 17: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/17.jpg)
Practical Reflection Strategy
• Dynamically Load Assemblies• Happens one time (at start up)
• Dynamically Load Types• Happens one time (at start up)
• Cast Types to a Known Interface• All method calls go through the interface
• No dynamic method calls – no MethodInfo.Invoke
• Avoid interacting with private members
@jeremybytes
![Page 18: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/18.jpg)
Various Data Sources
@jeremybytes
MongoDB
Amazon AWS
Microsoft Azure
WebAPI
CSV SOAP Service
Microsoft SQL Server
Oracle
JSON Hadoop
![Page 19: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/19.jpg)
Pluggable Repositories
@jeremybytes
WCF Service
Repository
CSV File
Repository
SQL Database
Repository
Application
![Page 20: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/20.jpg)
DEMO
Run-Time Binding
![Page 21: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/21.jpg)
Benefits of Dynamic Loading
•
•
•
@jeremybytes
![Page 22: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/22.jpg)
Assembly-Qualified Type Name
• Fully-qualified type name (namespace and type)
• Assembly Name
• Assembly Version
• Assembly Culture
• Assembly Public Key (for strongly-named assemblies)
@jeremybytes
![Page 23: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/23.jpg)
Limiting Reflection
private void FetchButton_Click(object sender, EventArgs e)
{
ClearListBox();
var people = repository.GetPeople();
foreach (var person in people)
PersonListBox.Items.Add(person);
ShowRepositoryType(repository);
}
No Reflection Here
Method calls through
IPersonRepository
@jeremybytes
![Page 24: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/24.jpg)
ScenarioClient #1
@jeremybytes
BusinessRuleBusinessRuleBusinessRule
Order EntryApplication
Client #2BusinessRuleBusinessRuleBusinessRule
Client #3BusinessRuleBusinessRuleBusinessRule
![Page 25: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/25.jpg)
Application
@jeremybytes
![Page 26: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/26.jpg)
Business Rule Interface
@jeremybytes
![Page 27: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/27.jpg)
Business Rules
@jeremybytes
Maximum Discount based
onCustomer Rating
Maximum of 1 Starshipper Order
Only 1Captain’s
ChairAllowed
Name Badgemust match
Customer Name
![Page 28: Introduction to XAML with WPFjeremybytes.com/Downloads/Slides-PracticalReflection.pdf · Introduction to XAML with WPF Author: Jeremy Created Date: 11/15/2016 8:02:41 PM](https://reader030.vdocuments.site/reader030/viewer/2022040309/5f29796bd627801bee3d8d12/html5/thumbnails/28.jpg)
Discovery Process
• Locate all assemblies in the “Rules” folder
• Load each assembly
• Enumerate the types in the assembly
• Check each type to see if it implements our Rule interface
• Create an instance of each Rule and add it to the Rule Catalog
@jeremybytes