Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we have a candy of params constructor to ValueTuple? #667

Closed
qaqz111 opened this issue Jun 9, 2017 · 3 comments
Closed

Can we have a candy of params constructor to ValueTuple? #667

qaqz111 opened this issue Jun 9, 2017 · 3 comments

Comments

@qaqz111
Copy link

qaqz111 commented Jun 9, 2017

For example:

public static void Log((string format, params object[] args) log,
    [CallerFilePath] string file = "",
    [CallerLineNumber] int line = 0,
    [CallerMemberName] string func = "")
{
    logger.Log(new LogEventInfo(log.level, logger.Name, null, log.message, log.args)
       .SetCallerInfo(file, line, func));
}

Without this, we can only archieve it like this:

public static void LogF<T1, T2>(this Logger logger, (LogLevel level, string message, T1 arg1, T2 arg2) log,
    [CallerFilePath] string file = "",
    [CallerLineNumber] int line = 0,
    [CallerMemberName] string func = "")
{
    logger.Log(new LogEventInfo(log.level, logger.Name, null, log.message, new[]{log.arg1, log.arg2})
       .SetCallerInfo(file, line, func));
}

public static void LogF<T1, T2, T3>(this Logger logger, (LogLevel level, string message, T1 arg1, T2 arg2, T3 arg3) log,
    [CallerFilePath] string file = "",
    [CallerLineNumber] int line = 0,
    [CallerMemberName] string func = "")
{
    logger.Log(new LogEventInfo(log.level, logger.Name, null, log.message, new[]{log.arg1, log.arg2, log.arg3})
       .SetCallerInfo(file, line, func));
}

//...

public static void LogF<T1, ..., T20>(this Logger logger, (LogLevel level, string message, T1 arg1, ..., T20 arg20) log,
    [CallerFilePath] string file = "",
    [CallerLineNumber] int line = 0,
    [CallerMemberName] string func = "")
{
    logger.Log(new LogEventInfo(log.level, logger.Name, null, log.message, new[]{log.arg1, ..., log.arg20})
       .SetCallerInfo(file, line, func));
}

So, this is an usage of mixing params parameters and optional parameters when can not simply overload.

There are some related post on Github and StackOverflow:

@HaloFour
Copy link
Contributor

HaloFour commented Jun 9, 2017

That doesn't work in C# without actually generating overloads for every possibly arity of tuple elements. Those tuple types are completely different and incompatible types.

@qaqz111
Copy link
Author

qaqz111 commented Jun 9, 2017

Ya... I've got confused with usage of C++ macro and templates.

Just forget it :p

@qaqz111 qaqz111 closed this as completed Jun 9, 2017
@HaloFour
Copy link
Contributor

HaloFour commented Jun 9, 2017

See #339 and dotnet/roslyn#5058.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants