shared project library - sddconf.comsddconf.com/brands/sdd/library/cross-platform-dev.pdfshared...
TRANSCRIPT
![Page 1: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/1.jpg)
![Page 2: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/2.jpg)
§
§
§
![Page 3: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/3.jpg)
Shared Project Portable Class Library
![Page 4: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/4.jpg)
![Page 5: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/5.jpg)
Shared Projects source + assets
§§§
Shared Project with C# source files, and images
![Page 6: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/6.jpg)
Shared.shprojNoteManager.cs
NoteItem.cs
Paperclip.png
Project defined by.shproj type
This project defines the included files as well as the build type (Compile, None, etc.), but does not actually generate any outputno assembly is produced
![Page 7: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/7.jpg)
compiled for the target
AnyNote.Droid.csprojNoteFragment.cs
FreehandFragment.cs
AnyNote.iOS.csproj
NoteViewController.cs
FreehandViewController.cs
AnyNote.WP8.csproj
NoteView.xaml.cs
DrawInkView.xaml.cs
![Page 8: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/8.jpg)
![Page 9: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/9.jpg)
Conditional Compilation
Class Mirroring
Partial Classes + Methods
![Page 10: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/10.jpg)
![Page 11: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/11.jpg)
![Page 12: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/12.jpg)
specific platform
![Page 13: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/13.jpg)
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.
‟
„− definition from Microsoft
![Page 14: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/14.jpg)
![Page 15: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/15.jpg)
![Page 16: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/16.jpg)
Feature .NET Framework
Windows Store Silverlight Windows
Phone (SL)Windows
Phone (Store) Xamarin
Core Libraries ✔ ✔ ✔ ✔ ✔ ✔
LINQ ✔ ✔ ✔ ✔ ✔ ✔
IQueryable ✔ ✔ ✔ 7.5+ ✔ ✔
Compression 4.5+ ✔ ✖ ✖ ✔ ✔
Data Annotations 4.0.3+ ✔ ✔ ✖ ✖ ✔
System.IO.File ✖ ✖ ✖ ✖ ✖ ✖
![Page 17: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/17.jpg)
![Page 18: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/18.jpg)
Pick only the framework targets you need right nowto give you as broad API reach as possible
![Page 19: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/19.jpg)
![Page 20: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/20.jpg)
![Page 21: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/21.jpg)
Selected profile has no constructor on StreamReaderwhich takes a string
void LoadNotes(string filename) {var reader = new StreamReader(filename);...
}
![Page 22: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/22.jpg)
Callbacks Factories
DependencyInjection
![Page 23: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/23.jpg)
![Page 24: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/24.jpg)
Shared Projects Portable Class Libraries
PROS CONSAll APIs available Can lead to
spaghetti code
Platform-specificlogic can be added directly
Cannot be unit tested on it's own
All file types can be shared
Must be shipped in source form
PROS CONSEnforcesarchitectural design
Limited APIs available
Can be unit tested separately
Can be difficult to share non-code files
Can be shipped in binary form (Nuget)
More work to integrate platform-specific code
![Page 25: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/25.jpg)
![Page 26: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/26.jpg)
§
![Page 27: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/27.jpg)
§
§
![Page 28: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/28.jpg)
§
> Loaded by assembly name at runtime> Nuget always prefers platform-specific library over PCL> Method dispatch is done at runtime
![Page 29: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/29.jpg)
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.
‟
„
![Page 30: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/30.jpg)
1.2.
3.
![Page 31: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/31.jpg)
§
PCL
public class AlertService{
bool Speak(string text){
return false;}
}
public class TTSService{
bool Speak(string text){
return false;}
}
![Page 32: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/32.jpg)
§
public class AlertService{
bool Speak(string text){
return false;}
}
public class TTSService{
bool Speak(string text){
...}
}
![Page 33: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/33.jpg)
§ lib/ Portable-Net45+NetCore45+MonoTouch+MonoAndroid/
MyComponent.dll // PCL VersionNet45/
MyComponent.dll // Desktop VersionXamarin.iOS10/
MyComponent.dll // iOS VersionMonoAndroid/
MyComponent.dll // Android VersionNetCore45/
MyComponent.dll // WinRT Versionwp8/
MyComponent.dll // WP 8 Versionwpa8/
MyComponent.dll // WP 8.1 Version
![Page 34: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/34.jpg)
§
![Page 35: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/35.jpg)
§assembly type method
call instance bool[MyComponent]Services.TTSService::Speak(String)
That means your app actually executes using the platform-specific assembly, even if it was compiled with the PCL definitions – this is exactly how .NET itself works; the compiler uses reference assemblies but the runtime uses a different set of DLLs
![Page 36: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/36.jpg)
![Page 37: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/37.jpg)
§
§
§
![Page 38: Shared Project Library - sddconf.comsddconf.com/brands/sdd/library/Cross-Platform-Dev.pdfShared Project Portable Class Library. Shared Projects source + assets!!! ... Silverlight Windows](https://reader030.vdocuments.mx/reader030/viewer/2022041112/5f16bf2dbdde1d7e623a7aeb/html5/thumbnails/38.jpg)
§
§
§
§