Skip to Content
Mobile Development with C#
book

Mobile Development with C#

by Greg Shackles
May 2012
Intermediate to advanced
174 pages
4h 21m
English
O'Reilly Media, Inc.
Content preview from Mobile Development with C#

Partial Classes

Earlier in this chapter, you saw that the abstraction pattern can be useful in catering to platform differences while still getting a lot of code reuse. However, in cases where most of a class can be shared across platforms and you simply want to provide some extensions for specific platforms, abstraction can sometimes become cumbersome. In these scenarios, C#’s support for partial classes can be very useful. Partial classes allow you to split the definition of a class across multiple files. These files will be merged at compile time and treated as though they were in the same file.

Partial classes are commonly found in platforms that make use of generated source code, such as ASP.NET Web Forms and Windows Forms. By using partial classes, the developer can work in an entirely separate file from the generated code, avoiding any collision between them but still providing a single class implementation to the compiler. This approach is also used by MonoTouch’s view controller designer files and Mono for Android’s resource classes.

The usefulness of partial classes is not limited to cases involving generated code. When combined with file linking, partial classes allow you to share the common source across each platform, but then also augment that with platform-specific extensions as needed. Since the different files are seen as one logical file in the eyes of the compiler, each part has full access to anything defined in the others, including private variables and methods. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Professional Cross-Platform Mobile Development in C#

Professional Cross-Platform Mobile Development in C#

Scott Olson, John Hunter, Ben Horgen, Kenny Goers
Xamarin: Cross-Platform Mobile Application Development

Xamarin: Cross-Platform Mobile Application Development

Jonathan Peppers, George Taskos, Can Bilgin

Publisher Resources

ISBN: 9781449338282Errata Page