SlideShare a Scribd company logo
1 of 40
Techniques for Cross
Platform .NET Development
Jeremy Hutchinson
@hutchcodes
What is “Cross Platform”
Android Phone
Android Tablet
Android Wear
iPhone
iPad
Apple Watch
Apple TV
Windows Phone
Windows Apps
Microsoft Band
Silverlight
XBox
.Net Core
.Net (ASP, WPF,
Winforms, Etc)
Supported Languages and Tools
Shared Logic
Platform A Platform B
using Windows.Storage;
namespace XPlat
{
public class UserData
{
public List<TodoItem> GetUserTodoList()
{
var userName = this.UserName;
//Make a call to a cloud resource
}
public string UserName
{
get
{
return ApplicationData.Current.LocalSettings.Values["UserName"].ToString();
}
set
{
ApplicationData.Current.LocalSettings.Values["UserName"] = value;
}
}
}
}
Linked Files Shared Project* Portable Class
Conditional Compile  
Partial Classes  
Inheritance   
Dependency Injection   
Share Code
Manage
Platform
Differences
How do we share code?
Linked Files
Shared Projects
UserData.cs
WinPhone8 Project Windows81 Project
Share Project
using System.IO.IsolatedStorage;
namespace XPlat
{
public class UserData
{
public List<TodoItem> GetUserTodoList()
{
var userName = this.UserName;
//Make a call to a cloud resource
}
public string UserName
{
get
{
return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString();
}
set
{
IsolatedStorageSettings.ApplicationSettings["UserName"] = value;
}
}
}
}
Conditional Compilation
#if DEBUG
public string Foo;
#else
public string bar;
#endif
Conditional Compilation
#if SILVERLIGHT
using System.IO.IsolatedStorage;
#else
using Windows.Storage;
#endif
namespace XPlat
{
public class UserData
{
public string UserName
{
get
{
#if SILVERLIGHT
return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString();
#else
return ApplicationData.Current.LocalSettings.Values["UserName"].ToString();
#endif
}
#if SILVERLIGHT
using System.IO.IsolatedStorage;
#else
using Windows.Storage;
#endif
namespace XPlat
{
public class UserData
{
public string UserName
{
get
{
#if SILVERLIGHT
return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString();
#else
return ApplicationData.Current.LocalSettings.Values["UserName"].ToString();
#endif
}
#if SILVERLIGHT
using System.IO.IsolatedStorage;
#endif
#if NETFX_CORE
using Windows.Storage;
#endif
#if __IOS__
using Foundation;
#endif
#if ANDROID
using Android.App;
using Android.Content;
#endif
Partial Classes
namespace XPlat
{
public partial class UserData
{
public List<TodoItem> GetUserTodoList()
{
//Get the username for local storage
var userName = this.UserName;
//Make a call to a cloud resource
}
}
}
using Windows.Storage;
namespace XPlat
{
public partial class UserData
{
public string UserName
{
get
{
return ApplicationData.Current.LocalSettings.Values["UserName"].ToString();
}
set
{
ApplicationData.Current.LocalSettings.Values["UserName"] = value;
}
}
}
}
using System.IO.IsolatedStorage;
namespace XPlat
{
public partial class UserData
{
public string UserName
{
get
{
return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString();
}
set
{
IsolatedStorageSettings.ApplicationSettings["UserName"] = value;
}
}
}
}
Inheritance
namespace XPlat
{
public abstract class UserDataBase
{
public List<TodoItem> GetUserTodoList()
{
//Get the username for local storage
var userName = this.UserName;
//Make a call to a cloud resource
}
public abstract string UserName { get; set; }
}
}
using Android.App;
using Android.Content;
namespace XPlat
{
public class UserData : UserDataBase
{
private readonly ISharedPreferences _preferences;
public UserData()
{
var ctx = Application.Context;
_preferences = ctx.GetSharedPreferences(ctx.PackageName, FileCreationMode.Private);
}
public override string UserName
{
get { return _preferences.GetString("UserName", ""); }
set
{
using (var editor = _preferences.Edit())
{
editor.PutString("UserName", value);
editor.Commit();
}
}
}
}
}
What do all these have in common?
namespace XPlat
var userData = new XPlat.UserData();
var todos = userData.GetUserTodoList();
Dependency Injection
namespace XPlat
{
public interface IStoredSettings
{
string UserName { get; set; }
}
}
namespace XPlat
{
public class UserData
{
private readonly IStoredSettings _storedSettings;
public UserData(IStoredSettings storedSettings)
{
_storedSettings = storedSettings;
}
public List<TodoItem> GetUserTodoList()
{
//Get the username for local storage
var userName = _storedSettings.UserName;
//Make a call to a cloud resource
throw new NotImplementedException();
}
}
}
using Foundation;
namespace XPlat.iOS
{
public class AppleSettings : IStoredSettings
{
public string UserName
{
get { return NSUserDefaults.StandardUserDefaults.StringForKey("UserName"); }
set
{
var defaults = NSUserDefaults.StandardUserDefaults;
defaults.SetString(value, "UserName");
defaults.Synchronize();
}
}
}
}
var userData = new XPlat.UserData(new XPlat.iOS.AppleSettings());
var todos = userData.GetUserTodoList();
Linked Files Shared Project* Portable Class
Conditional Compile  
Partial Classes  
Inheritance   
Dependency Injection   
Share Code
Manage
Platform
Differences
How do we share code?
Jeremy Hutchinson
Blog
hutchcodes.net
Twitter
@hutchcodes
Email
jrhutch@live.com

More Related Content

What's hot

Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12Vince Vo
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2Neeraj Mathur
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopSvetlin Nakov
 
Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)Pinaki Poddar
 
File Input & Output
File Input & OutputFile Input & Output
File Input & OutputPRN USM
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursorsinfo_zybotech
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?DicodingEvent
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database TutorialPerfect APK
 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8WindowsPhoneRocks
 
Android Architecure Components - introduction
Android Architecure Components - introductionAndroid Architecure Components - introduction
Android Architecure Components - introductionPaulina Szklarska
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring DataArturs Drozdovs
 
IMRCruisetoolbox: A Technical Presentation
IMRCruisetoolbox: A Technical PresentationIMRCruisetoolbox: A Technical Presentation
IMRCruisetoolbox: A Technical PresentationGeertjan Wielenga
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and OutputEduardo Bergavera
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Rebecca Grenier
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)Oum Saokosal
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputuanna
 

What's hot (19)

Java căn bản - Chapter12
Java căn bản - Chapter12Java căn bản - Chapter12
Java căn bản - Chapter12
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
 
Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
Dicoding Developer Coaching #20: Android | Apa itu Content Provider?
 
Android Database Tutorial
Android Database TutorialAndroid Database Tutorial
Android Database Tutorial
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
 
10 sharing files and data in windows phone 8
10   sharing files and data in windows phone 810   sharing files and data in windows phone 8
10 sharing files and data in windows phone 8
 
Android Architecure Components - introduction
Android Architecure Components - introductionAndroid Architecure Components - introduction
Android Architecure Components - introduction
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
IMRCruisetoolbox: A Technical Presentation
IMRCruisetoolbox: A Technical PresentationIMRCruisetoolbox: A Technical Presentation
IMRCruisetoolbox: A Technical Presentation
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access Slick: Bringing Scala’s Powerful Features to Your Database Access
Slick: Bringing Scala’s Powerful Features to Your Database Access
 
09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)09.1. Android - Local Database (Sqlite)
09.1. Android - Local Database (Sqlite)
 
Parameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple inputParameterization is nothing but giving multiple input
Parameterization is nothing but giving multiple input
 

Viewers also liked

MINI CLASE DE GEOMTRIA
MINI CLASE DE GEOMTRIAMINI CLASE DE GEOMTRIA
MINI CLASE DE GEOMTRIAAderson03
 
3Com 3C168915
3Com 3C1689153Com 3C168915
3Com 3C168915savomir
 
07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo
07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo
07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivoSierra Francisco Justo
 
Meetings in 2027: Predictions for the Future of the Hospitality Industry
Meetings in 2027: Predictions for the Future of the Hospitality IndustryMeetings in 2027: Predictions for the Future of the Hospitality Industry
Meetings in 2027: Predictions for the Future of the Hospitality IndustrySocial Tables
 
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...kosthom
 
Bola lisut-PERALATAN BOLA LISUT
Bola lisut-PERALATAN BOLA LISUTBola lisut-PERALATAN BOLA LISUT
Bola lisut-PERALATAN BOLA LISUTKhairul Nizam
 
Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017Majid Fatemian
 
Capítol 1 música amagada
Capítol 1 música amagadaCapítol 1 música amagada
Capítol 1 música amagadaJoanprofe
 
Microservices. The good, the bad and the ugly.
Microservices. The good, the bad and the ugly.Microservices. The good, the bad and the ugly.
Microservices. The good, the bad and the ugly.Sander Hoogendoorn
 
「民進党ゆるキャラ総選挙」人気を予測しました
「民進党ゆるキャラ総選挙」人気を予測しました「民進党ゆるキャラ総選挙」人気を予測しました
「民進党ゆるキャラ総選挙」人気を予測しましたToshihisa Tanaka
 
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...Dan Graur
 
Introduction to customer success by Guy Nirpaz @ Totango
Introduction to customer success  by Guy Nirpaz @ TotangoIntroduction to customer success  by Guy Nirpaz @ Totango
Introduction to customer success by Guy Nirpaz @ TotangoCEO Quest
 
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性Akina Noguchi
 
Fc - 5 fortes motivos meninas aprenderem a programar já
Fc - 5 fortes motivos meninas aprenderem a programar jáFc - 5 fortes motivos meninas aprenderem a programar já
Fc - 5 fortes motivos meninas aprenderem a programar jáJayme Nigri
 

Viewers also liked (20)

MINI CLASE DE GEOMTRIA
MINI CLASE DE GEOMTRIAMINI CLASE DE GEOMTRIA
MINI CLASE DE GEOMTRIA
 
3Com 3C168915
3Com 3C1689153Com 3C168915
3Com 3C168915
 
07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo
07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo
07 reason 2006 innovativo diseñovialmásamigable resumen ejecutivo
 
Meetings in 2027: Predictions for the Future of the Hospitality Industry
Meetings in 2027: Predictions for the Future of the Hospitality IndustryMeetings in 2027: Predictions for the Future of the Hospitality Industry
Meetings in 2027: Predictions for the Future of the Hospitality Industry
 
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
 
Bola lisut-PERALATAN BOLA LISUT
Bola lisut-PERALATAN BOLA LISUTBola lisut-PERALATAN BOLA LISUT
Bola lisut-PERALATAN BOLA LISUT
 
Yage
YageYage
Yage
 
Pasos de seleccion
Pasos de seleccionPasos de seleccion
Pasos de seleccion
 
Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017
 
Microservices
MicroservicesMicroservices
Microservices
 
Capítol 1 música amagada
Capítol 1 música amagadaCapítol 1 música amagada
Capítol 1 música amagada
 
Microservices. The good, the bad and the ugly.
Microservices. The good, the bad and the ugly.Microservices. The good, the bad and the ugly.
Microservices. The good, the bad and the ugly.
 
「民進党ゆるキャラ総選挙」人気を予測しました
「民進党ゆるキャラ総選挙」人気を予測しました「民進党ゆるキャラ総選挙」人気を予測しました
「民進党ゆるキャラ総選挙」人気を予測しました
 
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
Update version of the SMBE/SESBE Lecture on ENCODE & junk DNA (Graur, Decembe...
 
Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Spring Savings Events 2017Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Spring Savings Events 2017
 
Presentacion estrella rural
Presentacion estrella ruralPresentacion estrella rural
Presentacion estrella rural
 
Introduction to customer success by Guy Nirpaz @ Totango
Introduction to customer success  by Guy Nirpaz @ TotangoIntroduction to customer success  by Guy Nirpaz @ Totango
Introduction to customer success by Guy Nirpaz @ Totango
 
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
 
White paper on french companies in india
White paper on french companies in indiaWhite paper on french companies in india
White paper on french companies in india
 
Fc - 5 fortes motivos meninas aprenderem a programar já
Fc - 5 fortes motivos meninas aprenderem a programar jáFc - 5 fortes motivos meninas aprenderem a programar já
Fc - 5 fortes motivos meninas aprenderem a programar já
 

Similar to Techniques for Cross Platform .NET Development

Android Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageAndroid Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageDroidConTLV
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android JetpackAhmad Arif Faizin
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT TalkConstantine Mars
 
Architecture Components
Architecture Components Architecture Components
Architecture Components DataArt
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 StorageDiego Grancini
 
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS Nuxeo
 
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Khaled Anaqwa
 
Suportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EESuportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EERodrigo Cândido da Silva
 
Introduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformIntroduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformDominik Minta
 
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...DicodingEvent
 
FlashAir Android App Development
FlashAir Android App DevelopmentFlashAir Android App Development
FlashAir Android App DevelopmentFlashAir Developers
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotationjavatwo2011
 

Similar to Techniques for Cross Platform .NET Development (20)

Android Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, VonageAndroid Architecture Components - Guy Bar on, Vonage
Android Architecture Components - Guy Bar on, Vonage
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
 
Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS Devoxx08 - Nuxeo Core, JCR 2, CMIS
Devoxx08 - Nuxeo Core, JCR 2, CMIS
 
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
 
Android - Anatomy of android elements & layouts
Android - Anatomy of android elements & layoutsAndroid - Anatomy of android elements & layouts
Android - Anatomy of android elements & layouts
 
Suportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EESuportando Aplicações Multi-tenancy com Java EE
Suportando Aplicações Multi-tenancy com Java EE
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
Introduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformIntroduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile Platform
 
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
 
FlashAir Android App Development
FlashAir Android App DevelopmentFlashAir Android App Development
FlashAir Android App Development
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Dropwizard
DropwizardDropwizard
Dropwizard
 

Recently uploaded

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 

Recently uploaded (20)

Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 

Techniques for Cross Platform .NET Development

  • 1. Techniques for Cross Platform .NET Development Jeremy Hutchinson @hutchcodes
  • 2. What is “Cross Platform” Android Phone Android Tablet Android Wear iPhone iPad Apple Watch Apple TV Windows Phone Windows Apps Microsoft Band Silverlight XBox .Net Core .Net (ASP, WPF, Winforms, Etc)
  • 3. Supported Languages and Tools Shared Logic Platform A Platform B
  • 4.
  • 5. using Windows.Storage; namespace XPlat { public class UserData { public List<TodoItem> GetUserTodoList() { var userName = this.UserName; //Make a call to a cloud resource } public string UserName { get { return ApplicationData.Current.LocalSettings.Values["UserName"].ToString(); } set { ApplicationData.Current.LocalSettings.Values["UserName"] = value; } } } }
  • 6. Linked Files Shared Project* Portable Class Conditional Compile   Partial Classes   Inheritance    Dependency Injection    Share Code Manage Platform Differences How do we share code?
  • 8.
  • 9.
  • 11.
  • 12.
  • 13.
  • 14.
  • 16. using System.IO.IsolatedStorage; namespace XPlat { public class UserData { public List<TodoItem> GetUserTodoList() { var userName = this.UserName; //Make a call to a cloud resource } public string UserName { get { return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString(); } set { IsolatedStorageSettings.ApplicationSettings["UserName"] = value; } } } }
  • 17. Conditional Compilation #if DEBUG public string Foo; #else public string bar; #endif
  • 19. #if SILVERLIGHT using System.IO.IsolatedStorage; #else using Windows.Storage; #endif namespace XPlat { public class UserData { public string UserName { get { #if SILVERLIGHT return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString(); #else return ApplicationData.Current.LocalSettings.Values["UserName"].ToString(); #endif }
  • 20. #if SILVERLIGHT using System.IO.IsolatedStorage; #else using Windows.Storage; #endif namespace XPlat { public class UserData { public string UserName { get { #if SILVERLIGHT return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString(); #else return ApplicationData.Current.LocalSettings.Values["UserName"].ToString(); #endif }
  • 21. #if SILVERLIGHT using System.IO.IsolatedStorage; #endif #if NETFX_CORE using Windows.Storage; #endif #if __IOS__ using Foundation; #endif #if ANDROID using Android.App; using Android.Content; #endif
  • 23.
  • 24. namespace XPlat { public partial class UserData { public List<TodoItem> GetUserTodoList() { //Get the username for local storage var userName = this.UserName; //Make a call to a cloud resource } } }
  • 25. using Windows.Storage; namespace XPlat { public partial class UserData { public string UserName { get { return ApplicationData.Current.LocalSettings.Values["UserName"].ToString(); } set { ApplicationData.Current.LocalSettings.Values["UserName"] = value; } } } }
  • 26. using System.IO.IsolatedStorage; namespace XPlat { public partial class UserData { public string UserName { get { return IsolatedStorageSettings.ApplicationSettings["UserName"].ToString(); } set { IsolatedStorageSettings.ApplicationSettings["UserName"] = value; } } } }
  • 27.
  • 28.
  • 29.
  • 31. namespace XPlat { public abstract class UserDataBase { public List<TodoItem> GetUserTodoList() { //Get the username for local storage var userName = this.UserName; //Make a call to a cloud resource } public abstract string UserName { get; set; } } }
  • 32. using Android.App; using Android.Content; namespace XPlat { public class UserData : UserDataBase { private readonly ISharedPreferences _preferences; public UserData() { var ctx = Application.Context; _preferences = ctx.GetSharedPreferences(ctx.PackageName, FileCreationMode.Private); } public override string UserName { get { return _preferences.GetString("UserName", ""); } set { using (var editor = _preferences.Edit()) { editor.PutString("UserName", value); editor.Commit(); } } } } }
  • 33. What do all these have in common? namespace XPlat var userData = new XPlat.UserData(); var todos = userData.GetUserTodoList();
  • 35. namespace XPlat { public interface IStoredSettings { string UserName { get; set; } } }
  • 36. namespace XPlat { public class UserData { private readonly IStoredSettings _storedSettings; public UserData(IStoredSettings storedSettings) { _storedSettings = storedSettings; } public List<TodoItem> GetUserTodoList() { //Get the username for local storage var userName = _storedSettings.UserName; //Make a call to a cloud resource throw new NotImplementedException(); } } }
  • 37. using Foundation; namespace XPlat.iOS { public class AppleSettings : IStoredSettings { public string UserName { get { return NSUserDefaults.StandardUserDefaults.StringForKey("UserName"); } set { var defaults = NSUserDefaults.StandardUserDefaults; defaults.SetString(value, "UserName"); defaults.Synchronize(); } } } }
  • 38. var userData = new XPlat.UserData(new XPlat.iOS.AppleSettings()); var todos = userData.GetUserTodoList();
  • 39. Linked Files Shared Project* Portable Class Conditional Compile   Partial Classes   Inheritance    Dependency Injection    Share Code Manage Platform Differences How do we share code?

Editor's Notes

  1. Welcome to
  2. Most people think of Xamarin or Cordova or some other tool that allows you to target iOS, Android and Windows phones and tablets But it can also include wearables like Apple Watch, Android Wear, MS Band  Also includes Winforms, WPF and maybe a legacy Silverlight app Also includes Asp.Net and Asp.Net Core
  3. Have a bunch of code that is the same Some code that is platform specific Goal is to minimize the platform specific code
  4. No Copy/Paste
  5. 2 Methods: GetUserTodoList() would be the same code for all platforms
  6. Linked Files and Shared Projects are share then compile Portable Class is Compile then Share Shared Projects aren’t available from ASP.NET or ASP.NET CORE
  7. Advantage is it can be used with any two projects Disadvantage renaming a file breaks the link
  8. Shared project has no references Just a container that holds files shared between the projects They are pulled in and compiled with each project
  9. Reference the shared project from the other projects
  10. Can’t use shared with all types of projects (not ASP.NET or ASP.NET CORE)
  11. Sharing with WindowsPhone 8 means a different Namespace and Different API for local storage
  12. Right click on a project->properties Windows phone 8.1 Defines NETFX_CORE and WINDOWS_PHONE_APP Windows 8.1 and UWP both also define NETFX_CORE
  13. I can open the linked file from both projects, changes made in one are shown in the other File only exists in the original project. Renaming the original file breaks the link.
  14. If you include WP8, WP8.1, Win8.1, UWP, Android and iOS your usings look like this We need a better way
  15. Splits the definition of a class over two or more files.
  16. The UserData class defined in your shared project looks like this
  17. Win8.1, WinPhone8.1 and UWP UserData looks like this
  18. WindowsPhone 8 looks like this This looks pretty good but for both techniques all the projects must be in the same solution Shared projects don’t work with some project types
  19. Lowest common denominator If you choose .NET 4 or WinPhone 8.1 you don’t get Compression and Data annotation You don’t get Dynamic with WinPhone 8.1 Can’t combine Silverlight 5 and ASP.NET Core
  20. Abstract classes contain 1+ abstract method Abstract classes can’t be instantiated and require subclasses to provide implementations for the abstract methods
  21. This is the definition of the UserDataBase class in the Portable Class Library Note the class is abstract so it can’t be instantiated Defines UserName property as Abstract so sub-classes must implement it.
  22. User Data Class in the Android project Note we inherit from UserDataBase and Override the UserName property.
  23. All these techniques so far have put the all shared code in the XPlat namespace We could implement inheritance in XPlat.Droid but if a calling class is completely shared through a PCL in the XPlat it can’t access the platform specific code without additional techniques to handle usings Calling code would also all look the same
  24. With this technique you can pass in the platform specific implementation that will be used.
  25. Define this interface in the PCL
  26. Calling code would look like this You can manually inject the dependency or use a framework like StructureMap, Unity, Ninject or something else.
  27. Linked Files and Shared Projects are share then compile Portable Class is Compile then Share Shared Projects aren’t available from ASP.NET or ASP.NET CORE