Date post: | 02-Jul-2015 |
Category: |
Software |
Upload: | falafelsoftware |
View: | 361 times |
Download: | 0 times |
Share More Code on !iOS, Android, & Windows!w/ Portable Class Libraries!
James Montemagno!Developer Evangelist, Xamarin!@JamesMontemagno!
How to reach all platforms What are PCLs How do we create them How do we share them
Agenda!
How to reach all platforms What are PCLs How do we create them How do we share them
iOS and Android in C#? How can this be!
Xamarin’s Unique Approach!
Native With !Code Sharing!
Windows APIs!
iOS APIs | 100% Coverage!
Android APIs | 100% Coverage!
C# Runs on 2.5+ Billion Devices!!
How do we share code?
File Linking == “Fun”!
Linking files is HORRIBLE
Shared Projects! • Drop dead simple
code sharing • Glorified File Linking • Allows Compiler
Directives in Code • Best for “Inner” app
sharing
Sharing Code Should Be Easy
How to reach all platforms What are PCLs How do we create them How do we share them
• 1 Assembly • Multiple Platforms • Including: • Android • iOS
Portable Class Libraries!
What can you use?!
It’s complicated
DO NOT READ THIS Portable class libraries are made up of two concepts: an API contract (﴾AKA: reference assembly)﴿ and an implementation. Most of the time, those concepts exist together in a single assembly. PCLs, however, have the flexibility to have multiple implementations for a single API contact. This 2nd case is useful, when implementations need to be platform-‐specific in some way (﴾ex: X86 vs. ARM or Android vs. iOS)﴿. In this case, a PCL would have a single reference assembly that consumers compile with, and then implementations available to be deployed for each of the supported platforms. In all cases, PCLs expose a surface area that is compatible with multiple .NET platforms.
What is a PCL?!
• Centralized Code Sharing • How you expect it to work • Debug seamlessly into and out of PCL
• Project/Assembly Sharing • NuGet
Benefits!
• Platform-‐specific libraries can’t be referenced • E.g. No Silverlight Control Toolkit • No P/Invoke to C/C++
• PCL is a subset of .NET
Platform Independent APIs!
What is out there?
• Async for .NET Framework 4, Silverlight 4 and 5, and WP 7.5 & 8 • Microsoft BCL Build Components • Microsoft BCL Portability Pack • Microsoft Composition • Microsoft Compression • Microsoft HTTP Client Libraries • Microsoft Immutable Collections • Microsoft ASP.NET SignalR .NET Client • ODataLib
Microsoft NuGet PCLs!
• Easier to use • Easier to create • True Cross Platform
Portable Class Libraries
Available to Everyone!!
• Xamarin.Forms • MvvmCross • ReactiveUI • Akavache – Async Persistent Key-‐Value Store • Splat – Image Loading • Budgie – Twitter Library • Azure Mobile Services • Json.Net
• SO MANY MORE!!!
Awesome Portable Class Libraries!
Well Documented!
How to reach all platforms What are PCLs How do we create them How do we share them
2 Ways to Create Standard PCL Advanced PCL
• Reference Assembly • API Contract
• Implementation
2 Parts to a PCL!
Standard - PCL Profile Only!
Limited to PCL Subset Easy to manage Easy to share
Demo
• Reference Assembly • API Contract
• Implementation
2 Parts to a PCL!
Advanced - Bait and Switch!
Tap into platform specific code Your users never know! Pure compilation magic ;)﴿
Demo
Why this works!• If we match • Assembly Name • Version • Class Structure
• PCL binary is replaced with platform binary
How to reach all platforms What are PCLs How do we create them How do we share them
• NuSpec • NuPackage
2 Parts "!
Demo
You can read this now Portable class libraries are made up of two concepts: an API contract (﴾AKA: reference assembly)﴿ and an implementation. Most of the time, those concepts exist together in a single assembly. PCLs, however, have the flexibility to have multiple implementations for a single API contact. This 2nd case is useful, when implementations need to be platform-‐specific in some way (﴾ex: X86 vs. ARM or Android vs. iOS)﴿. In this case, a PCL would have a single reference assembly that consumers compile with, and then implementations available to be deployed for each of the supported platforms. In all cases, PCLs expose a surface area that is compatible with multiple .NET platforms.
What is a PCL?!
• Getting Started with PCL • http://bit.ly/pcl-‐get-‐started
• Bait and Switch • http://log.paulbetts.org/the-‐bait-‐and-‐
switch-‐pcl-‐trick/
Resources!
Get Started Today: xamarin.com/download"
Q & A!!Get your free C# t-shirt:!xamarin.com/shirt!
Find Me:!@JamesMontemagno | @XamarinHQ!http://motzcod.es | http://blog.xamarin.com!