From 7cbfecd6a9c63a9f95a08b12cfac9bd682ba2299 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Fri, 10 Feb 2017 22:12:24 +0000 Subject: [PATCH] [csharp]Cleaner implementation on YogaLogger --- csharp/Facebook.Yoga/YogaLogger.cs | 48 ++++++++++-------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/csharp/Facebook.Yoga/YogaLogger.cs b/csharp/Facebook.Yoga/YogaLogger.cs index 52731af7..68d946e6 100644 --- a/csharp/Facebook.Yoga/YogaLogger.cs +++ b/csharp/Facebook.Yoga/YogaLogger.cs @@ -8,17 +8,14 @@ */ using System; -using System.Runtime.InteropServices; namespace Facebook.Yoga { internal static class YogaLogger { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void Func(YogaLogLevel level, string message); private static bool _initialized; - private static Func _managedLogger = null; public static Func Logger = null; @@ -26,42 +23,27 @@ namespace Facebook.Yoga { if (!_initialized) { - _managedLogger = (level, message) => { - if (Logger != null) - { - Logger(level, message); - } - if (level == YogaLogLevel.Error) - { - throw new InvalidOperationException(message); - } - }; -#if __IOS__ - Native.YGInteropSetLogger(ManagedLogger); -#else - Native.YGInteropSetLogger(_managedLogger); -#endif + Native.YGInteropSetLogger(LoggerInternal); _initialized = true; } } #if __IOS__ - delegate void ManagedLoggerCallback(YogaLogLevel level, string message); - - [ObjCRuntime.MonoPInvokeCallback(typeof(ManagedLoggerCallback))] - public static void ManagedLogger(YogaLogLevel level, string message) - { - if (Logger != null) - { - Logger(level, message); - } - - if (level == YogaLogLevel.Error) - { - throw new InvalidOperationException(message); - } - } + [ObjCRuntime.MonoPInvokeCallback(typeof(Func))] #endif + public static void LoggerInternal(YogaLogLevel level, string message) + { + if (Logger != null) + { + Logger(level, message); + } + + if (level == YogaLogLevel.Error) + { + throw new InvalidOperationException(message); + } + } + } }