Xamarin.Forms Projects
上QQ阅读APP看书,第一时间看更新

Xamarin and Mono

Xamarin is a developer platform that is used to develop native applications for iOS (Xamarin.iOS), Android (Xamarin.Android), andmacOS (Xamarin.Mac). It is technically a binding layer on top of these platforms. Binding to platform APIs enables .NET developers to use C# (and F#) to develop native applications with the full capacity of each platform. The C# APIs we use when we develop apps with Xamarin are more or less identical to the platform APIs, but they are .NETified. For example, APIs are often customized to follow .NET naming conventions and the Android set and get methods are often replaced by properties. The reason for this is that APIs should be easier to use for .NET developers.

Mono (https://www.mono-project.com) is an open source implementation of the Microsoft .NET framework, which is based on the European Computer Manufacturers Association (ECMA) standards for C# and the Common Language Runtime (CLR). Mono was created to bring the .NET framework to platforms other than Windows. It is part of the .NET Foundation (http://www.dotnetfoundation.org), an independent organization that supports open development and collaboration involving the .NET ecosystem.

With a combination of the Xamarin platforms and Mono, we can use both the platform-specific APIs and the platform-independent parts of .NET, including namespaces, systems, System.Linq, System.IO, System.Net, and System.Threading.Tasks.

There are several reasons for using Xamarin for mobile app development, which we will cover in the following sections.

When .NET 5 is released, it will partly replace Mono. We will get one unified Base Class Library ( BCL) for all the .NET platforms. Xamarin.iOS will still run on the Mono runtime because iOS apps need to be Ahead Of Time ( AOT) compiled. The .NET runtime (currently called .NET Core Runtime) will not support AOT.

Code sharing

If we use one common programming language for multiple mobile platforms (and even server platforms), then we can share a lot of code between our target platforms, as illustrated in the following diagram. All code that isn't related to the target platform can be shared with other .NET platforms. Code that is typically shared in this way includes business logic, network calls, and data models:

There is also a large community based around the .NET platforms, as well as a wide range of third-party libraries and components that can be downloaded from NuGet (https://nuget.org) and used across the .NET platforms.

Code sharing across platforms leads to shorter development times. It also produces apps of a higher quality because, for example, we only need to write the code for business logic once. There is a lower risk of bugs and are also be able to guarantee that a calculation returns the same result, regardless of what platform our users use.

Using existing knowledge

For .NET developers who want to start building native mobile apps, it is easier to just learn the APIs for the new platforms than it is to learn programming languages and APIs for both old and new platforms.

Similarly, organizations that want to build native mobile apps can use existing developers with their knowledge of .NET to develop apps. Because there are more .NET developers than Objective-C and Swift developers, it's easier to find new developers for mobile app development projects.