How to structure Xamarin library containing iOS & Android bindings? - c#

I'd like to create a library, which can be used within Xamarin projects.
I also want to reuse iOS as well as Android libraries (static lib & jar). Therefore I created a solution which contains an Android binding project as well as an iOS binding project.
To expose this functionality I'd like to create a single wrapper class (within a shared project), which forwards the call to the appropriate native lib. I first thought that this could be done with the use of if-makros. Unfortunately, it seems like I can't add references to a shared project, which means I am not able to call the binded methods.

Could you expose an interface in your shared library that each platform implements with their specific binding implementation and reference everything through that?

Related

Implement missing platform for MvvmCross plugin

I want to use an MvvmCross plugin in my project, however one of my platforms is Wpf.
Unfortunately there's no Wpf implementation (https://github.com/brianchance/MvvmCross-UserInteraction).
What is the proper way of adding WPF platform implementation to my project?
More specifically, my questions are:
In the implementation I need to use UI controls and components to display message boxes, thus should it be "WPF Custom Control Library" or can I use just standard "Class library"?
Do I have to add Nuget packages Mvvm.CrossCore and Mvvm UserInteractionPlugin to my WPF implementation library?
Ideally I'd like to create and test WPF implementation in my own project and then contribute it to plugin repo on github.
The simplest would be to clone the original repo. Then add a new Class Library project for your WPF implementation.
If you look at the existing Windows Store project, it simply adds a project reference to the UserInteraction (PCL) project.
Create a UserInteraction class that implements IUserInteraction. Add your WPF implementation there.
Include the Plugin class so it will auto-register in MvvmCross.
You can then modify the existing .nuspec file to add entries for your WPF assemblies.
This is pretty much how all MvvmCross plugins work.

Xamarin iOS - How do I include dependencies when binding libraries?

I have an Obj-C native library libCMX.a that I wish to create C# bindings for, but the library has multiple dependencies, e.g. JASidePanels with a couple of .m and .h files.
How can I include these in the Xamarin binding project so they are linked correctly into the resulting DLL?
I know I can specify Frameworks in the LinkWith attribute, but how do I include pure code dependencies in form of main and header files?
EDIT: The library is proprietary (Cisco CMX SDK), I do not have access to the source code.
EDIT 2: The library is part of a framework (CMX.framework), from which I have extracted the extensionless archive and renamed it to libCMX.a to match default library naming for Xamarin.
You can reference multiple native libraries in your binding project, the combined set of libraries will be linked into your application.
You only need to surface the APIs for libraries that you want to invoke/call. For the rest, just include the binary dependencies.
You will need to compile those into the static library (libMyLibrary.a) you are binding to C#.

How to use same class library on WCF and Silverlight application

Hi I would like to use the same class library from my Silverlight application and WCF based service. I created a Silverlight C# class library and found the WCF service does not allow adding reference to Silverlight Project types. So
What should i do to make this work?
Can Silverlight invoke methods on Silverlight Class library if it communicates with WCF service?
Is silverlight always this hard?
Portable Class Library
http://msdn.microsoft.com/en-us/library/gg597391.aspx
Try making 2 class libraries, one for Silverlight and one for WCF. Both use the same C# source code files. In the second project, you can add the files as link (In Visual Studio in solution explorer: add existing item, and then in the drop-down Add button, choose "Add as link".
That's how we solved it for shared code. You have to limit yourself to library calls that exist in both worlds though.
Now it is easy :D - just use the .shared trick. It allows you to share the same code between server and client. Look here: http://msdn.microsoft.com/en-us/library/ee707371(v=vs.91).aspx
PS.: You can even add conditional directives on your .shared classes, like this:
#if SILVERLIGHT
MessageBox.Show("yay, I will run only on silverlight");
#endif

Including xib(s) / nib(s) in a MonoTouch Binding project

I'm trying to create a re-useable MonoTouch library that contains Views defined in a xib, and Controller code written in Objective-C.
I have created a static Objective-C library that contains the relevant controller code with all the outlets declared.
A static *.a library obviously can't contain xib/nib data (if this is possible can someone please let me know), so I can't embed the xibs/nibs in this library.
I have created a 'MonoTouch Binding Project' that defines the relevant wrapper classes.
This is where I would ideally also embed the xibs/nibs, and have them included in the app bundle of any final project that links this dll.
Now looking at what a 'MonoTouch Library Project' does with xibs - it compiles it to a nib using ibtool, and then embeds it as a resource in the resultant library dll using the /res option of smcs. I'm assuming this is triggered because the xib file is marked with a "InterfaceDefinition" build action in the project.
However a 'MonoTouch Binding Project' has no "InterfaceDefinition" build action. Is this possible at all using a MonoTouch Binding Project?
I haven't tried it yet, but I'm assuming I could get it working manually by combining what the Library project does with ibtool and smcs /res and what the Binding Project does with btouch and smcs. But I'd rather avoid this, I'm enjoying the lack of Makefiles lately.
Xamarin/MonoTouch team - any plans to add this to Binding Projects in the future? Any way to force it to work currently?

linking silverlight class to web app

Have written all the code in a silverlight class library (dll) and linked this same library to my web app and silverlight app, is there a way to avoid the "Compiler Error Message: CS0433" or do I have to create a separate dll for the web app?
Error mostly occurs when XElement is called...
You need to create two projects, but can add the same CS file using Add Existing Item as a Link. http://msdn.microsoft.com/en-us/library/9f4t9t92.aspx explains it.
http://www.scip.be/index.php?Page=ArticlesNET28 is a nice read with related info.
Do you mean you are referencing a single dll from both the web app and the Silverlight app? I would have two versions of the dll (and two project files); one built for regular .NET (for use in the web app), and one for Silverlight; the main difference being the target framework and the references.
If you don't want to deal with having to maintain two project files (when you add classes etc), then you can use this trick to reduce this overhead.

Categories