SlideShare a Scribd company logo
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 - Chapter12
Vince Vo
 
ASP.Net Presentation Part2
ASP.Net Presentation Part2ASP.Net Presentation Part2
ASP.Net Presentation Part2
Neeraj Mathur
 
Map-Reduce and Apache Hadoop
Map-Reduce and Apache HadoopMap-Reduce and Apache Hadoop
Map-Reduce and Apache Hadoop
Svetlin 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 & Output
PRN USM
 
ADO.net control
ADO.net controlADO.net control
ADO.net control
Paneliya Prince
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
info_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 Tutorial
Perfect APK
 
Intake 38 10
Intake 38 10Intake 38 10
Intake 38 10
Mahmoud Ouf
 
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
WindowsPhoneRocks
 
Android Architecure Components - introduction
Android Architecure Components - introductionAndroid Architecure Components - introduction
Android Architecure Components - introduction
Paulina Szklarska
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
Arturs Drozdovs
 
IMRCruisetoolbox: A Technical Presentation
IMRCruisetoolbox: A Technical PresentationIMRCruisetoolbox: A Technical Presentation
IMRCruisetoolbox: A Technical Presentation
Geertjan Wielenga
 
Oracle 10g
Oracle 10gOracle 10g
Oracle 10g
Svetlin Nakov
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo 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 input
uanna
 

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 GEOMTRIA
Aderson03
 
3Com 3C168915
3Com 3C1689153Com 3C168915
3Com 3C168915
savomir
 
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
Sierra 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 Industry
Social Tables
 
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
Περιβαλλοντικά οφέλη και επιπτώσεις από την αξιοποίηση της γεωθερμίας στο αστ...
kosthom
 
Bola lisut-PERALATAN BOLA LISUT
Bola lisut-PERALATAN BOLA LISUTBola lisut-PERALATAN BOLA LISUT
Bola lisut-PERALATAN BOLA LISUT
Khairul Nizam
 
Yage
YageYage
Pasos de seleccion
Pasos de seleccionPasos de seleccion
Pasos de seleccion
Heiner Mercado
 
Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017Securing MicroServices - ConFoo 2017
Securing MicroServices - ConFoo 2017
Majid Fatemian
 
Microservices
MicroservicesMicroservices
Microservices
Artur Prado
 
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
 
Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Spring Savings Events 2017Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Spring Savings Events 2017
Sadigh Gallery Ancient Art, Inc.
 
Presentacion estrella rural
Presentacion estrella ruralPresentacion estrella rural
Presentacion estrella rural
Juan Andres Martin Marin
 
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
CEO Quest
 
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
インクルーシブ教育システムの構築に向けたスクールワイドな支援モデルの可能性
Akina Noguchi
 
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
Federation of Indian Chambers of Commerce & Industry (FICCI)
 
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, Vonage
DroidConTLV
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
Matteo Bonifazi
 
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 Jetpack
Ahmad Arif Faizin
 
Architecture components - IT Talk
Architecture components - IT TalkArchitecture components - IT Talk
Architecture components - IT Talk
Constantine Mars
 
Architecture Components
Architecture Components Architecture Components
Architecture Components
DataArt
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
Nakka Srilakshmi
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
Diego 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
 
Android - Anatomy of android elements & layouts
Android - Anatomy of android elements & layoutsAndroid - Anatomy of android elements & layouts
Android - Anatomy of android elements & layouts
Vibrant Technologies & Computers
 
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
Rodrigo Cândido da Silva
 
Codemotion appengine
Codemotion appengineCodemotion appengine
Codemotion appengine
Ignacio Coloma
 
Java Tutorial 1
Java Tutorial 1Java Tutorial 1
Java Tutorial 1
Tushar Desarda
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
 
Introduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile PlatformIntroduction to Xamarin Mobile Platform
Introduction to Xamarin Mobile Platform
Dominik 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 Development
FlashAir Developers
 
比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
 
Dropwizard
DropwizardDropwizard
Dropwizard
Scott Leberknight
 

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

Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 

Recently uploaded (20)

Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 

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