简体   繁体   English

Xamarin.Forms PCL

[英]Xamarin.Forms PCL

i was just wondering what the benefits are in using PCL with Xamarin.Forms. 我只是想知道将PCL与Xamarin.Forms一起使用有什么好处。 I mean you share the Code between each Platform anyway. 我的意思是您还是要在每个平台之间共享代码。 In Xamarins native approach it is quite clear. 在Xamarins原生方法中,这很清楚。 So maybe anybody can tell me why to use PCL in Xamarin.Forms? 因此,也许有人可以告诉我为什么在Xamarin.Forms中使用PCL?

PCL allows the maximum in code sharing across platforms. PCL允许最大程度地跨平台共享代码。 PCL will by it's very nature limit you to using only those API's that can be shared from platform to platform. PCL本质上将限制您只能使用可以在平台之间共享的那些API。

While you can use Shared Projects, you will find yourself using compiler directives and making coding sacrifices that can lead to bad coding practices across anything but the smallest of projects. 尽管可以使用共享项目,但是您会发现自己使用了编译器指令并做出了牺牲代码的工作,这可能导致除最小的项目之外的所有项目都出现不良的编码实践。

Using the Xamarin Forms 2.3.3 or later you can of course embed Platform Specific Controls in your Xamarin Forms pages in your PCL and they will only render when run on the platform. 当然,使用Xamarin Forms 2.3.3或更高版本,您当然可以在PCL的Xamarin Forms页面中嵌入特定于平台的控件,并且仅在平台上运行时才会呈现。

In addition of maximum code sharing, it allows you to follow best practices like SOLID. 除了最大程度的代码共享外,它还允许您遵循SOLID之类的最佳实践。

Also, please remember that there are 3 choices (not only 2): 另外,请记住,有3个选择(不仅是2个):

  • Portable Class Library 可移植类库
  • Shared Library 共享图书馆
  • .NET Standard Library .NET标准库

.NET Standard Library is still an ongoing work in process, so it's not there yet. .NET标准库仍在进行中,因此尚不存在。 But, it will be the way to go!. 但是,这将是必经之路! So, PCLs today can give you an excelent migration path to the .NET Standard Library way tomorrow. 因此,今天的PCL可以为您明天向.NET标准库的方式提供出色的迁移路径。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM