官术网_书友最值得收藏!

  • Xamarin Blueprints
  • Michael Williams
  • 186字
  • 2021-07-08 11:48:19

Shared projects

We are going to delve into our first technique for sharing code between different platforms. This is what Xamarin wants us to achieve, and reuse as much code as possible. The biggest disadvantage when developing natively is two different language, and we can't reuse anything.

Let's create our first shared project:

Our shared project will be used to contain the GalleryItem model, so whatever code we include in this shared project can be accessed by both the iOS and Android projects:

In the preceding screenshot, have a look at the Solution explorer, and notice how the shared project doesn't contain anything more than .cs code sheets. Shared projects do not have any references or components, just code that is shared by all platform projects. When our native projects reference these shared projects, any libraries being referenced via using statements come from the native projects.

Now we must have the iOS and Android projects reference the shared project; right-click on the References folder and select Edit References:

Select the shared project you just created and we can now reference the GalleryItem object from both projects.

主站蜘蛛池模板: 宁河县| 威远县| 尖扎县| 广饶县| 宁都县| 肇东市| 哈密市| 贺州市| 枣阳市| 屯留县| 大同市| 忻州市| 徐闻县| 建德市| 湖州市| 高清| 遂溪县| 镇原县| 镇安县| 磴口县| 渝中区| 绥棱县| 甘南县| 阜康市| 宿松县| 溆浦县| 崇州市| 会东县| 贵阳市| 大英县| 乌鲁木齐县| 民权县| 恭城| 县级市| 晋城| 舟曲县| 龙门县| 牙克石市| 吉木萨尔县| 彭州市| 石家庄市|