So my company comes from a completely C# .Net environment, so naturally we are looking at Mono for mobile development. We have a very extensive windows platform library which I was able to port most of it as an Android Class Library. The idea being that this Android Class Library will be our mobile platform library which can be reused in the future for MonoTouch (Haven't tested, but read that MonoTouch project can reference Android Class Libraries as long as there is no Android specific code). Within the library though, there are plenty of logging statements, which for the windows environment just end up being trace statements(wrapped in a custom helper class). We want to retain the logging statements and based on the current environment(iOS or Android), just translate those into native logging.
I was planning to use partial declarations for the logging in the mobile platform library and have the Android and iOS specific libraries contain the implementations for those partial logging methods. But that fell apart when I realized partials do not work between assemblies.
So now I am not sure how to go about this. The only thing I can think of if having two separate iOS and Android platform libraries and linking the same files. (Xamarin might have a logging class that does this but we still need to come up with a pattern for any other future abstractions)
Any advice is appreciated. We are still in the experimental/planning phase so there is a chance we might be overlooking something, please let us know if that is the case.
Thanks.
Edit
Lets say I have the following simple static class.
public static class TraceHelper
{
public static void WriteLine(string message)
{
// Validation and preprocessing
Trace.WriteLine(message);
}
}
And I have hundreds of calls to this method within the mobile platform library. Now lets say I reference this library in my Android application, is there any way to override the implementation of TraceHelper.WriteLine() without modifying the library itself?
Update
We ended up creating Android and iOS libraries that implemented the missing .NET functionality. Just wrap the native equivalent functionality, in the same .NET namespace and class. EX:
using Android.Util;
namespace System.Diagnostics
{
public static class Trace
{
#region Non-Public Data Members
private const string Tag = "Trace";
#endregion
public static void WriteLine(string message)
{
Log.WriteLine(LogPriority.Verbose, Tag, message);
}
}
}
ILog
interface via a static factory and have no knowledge of the platform specifics being used. (also helps to attach different loggers within the same platform as desired)