Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2013 C# function declaration => sign

This code gives me error in vs2013 ... I don't now why ... somebody can help me ?! my problem is i don't know what the => is meant for and how to fix the errors

using System;

namespace SmartStore.Core.Logging
{
    public static class LoggingExtensions
    {
        public static bool IsDebugEnabled(this ILogger l)                                               => l.IsEnabledFor(LogLevel.Debug);


    public static void Fatal(this ILogger l, string msg)                                            => FilteredLog(l, LogLevel.Fatal, null, msg, null);
    public static void Fatal(this ILogger l, Func<string> msgFactory)                               => FilteredLog(l, LogLevel.Fatal, null, msgFactory);

    public static void ErrorsAll(this ILogger logger, Exception exception)
    {
        while (exception != null)
        {
            FilteredLog(logger, LogLevel.Error, exception, exception.Message, null);
            exception = exception.InnerException;
        }
    }

    private static void FilteredLog(ILogger logger, LogLevel level, Exception exception, string message, object[] objects)
    {
        if (logger.IsEnabledFor(level))
        {
            logger.Log(level, exception, message, objects);
        }
    }

    private static void FilteredLog(ILogger logger, LogLevel level, Exception exception, Func<string> messageFactory)
    {
        if (logger.IsEnabledFor(level))
        {
            logger.Log(level, exception, messageFactory(), null);
        }
    }
}
like image 403
StalCaiRe Avatar asked Jun 16 '26 15:06

StalCaiRe


1 Answers

In this case, the => is denoting an expression-bodied member and is equivalent to:

public static void Fatal(this ILogger l, Func<string> msgFactory) 
{ 
    return FilteredLog(l, LogLevel.Fatal, null, msgFactory); 
}

However, this syntax was introduced in C# 6 which requires the Visual Studio 2015 compiler or newer. Switch to the method syntax or upgrade your version of visual studio.

like image 100
BradleyDotNET Avatar answered Jun 19 '26 04:06

BradleyDotNET