How may I use the same file for two particular platforms? (iOS, Android)

CollinIrwinCollinIrwin USMember ✭✭

EDIT: See my own replies below.

My question's reason for existence:

I'm working on a Xamarin cross platform app (using PCL + forms), and I need to use System.Security.Cryptography and System.Net.Sockets. My PCL does not let me use either of these. My PCL is profile 78. I only intend to develop for mobile devices (iOS, Android) in particular. Windows phone would be a cherry on top, but is definitely not a requirement. I know that Android and iOS support both of these namespaces. I could simply use the DependencyService and put the same exact file in both my platform ios and platform droid folders, but then every time I edit one I would have to copy paste to the other.

My question:
How can I either:

A. Modify my PCL to let me use System.Net.Sockets and System.Security.Cryptography

B. Use the same C# file for both iOS and Android (i.e. my AES class or my Communications class that I currently believe I have to copy-paste in two places).

C. Some other alternative that you may notice while reading this post.

Best Answer

Answers

  • CollinIrwinCollinIrwin USMember ✭✭
    edited May 2015

    Well... I think I found the answer to using the same C# file in multiple platforms, or rather the solution to my ultimate question of using System.Crypto and System.Sockets:

    http://developer.xamarin.com/guides/cross-platform/application_fundamentals/shared_projects/

    For some reason I didn't think you could do both PCL and Shared in the same solution. I was wrong there. I also didn't realize that the option for making these directories was under the Add New Project - > .Net, I expected it to be under Cross-Platform.

    I still don't know how to modify my PCL's assemblies, but that isn't needed any more so I'll push that off for later.

  • CollinIrwinCollinIrwin USMember ✭✭
    edited May 2015

    Okay so now I have a PCL, with viewmodels for Xamarin.Forms, a shared project, and platform projects.

    The PCL's viewModels need to make use of the classes in the shared project, but I must be missing something as I am getting "The type or namespace could not be found. Are you missing an assembly reference?

    But I can't include the reference because then my shared project loses its ability to access System.Net.Sockets and System.Security.Cryptography

    I'm beginning to feel like it would be easier to just make the whole project a shared project rather than messing around with part PCL/part shared project. I am also seemingly losing understanding of why PCL is useful in the first place. Is it purely a tool that limits you to only a specific subset of .NET?

Sign In or Register to comment.