I prefer Environment.NewLine over "\r\n" whenever possible, even though this project is Windows-only. I was wondering if there was a way to use it as a default value of an optional parameter.
Consider the extension method
public static string ToSummaryString<T>( this IEnumerable<T> items, string delimiter = Environment.NewLine) and the compile time error
Default parameter value for 'delimiter' must be a compile-time constant
I tried using parameter attributes too, with a similar fate
public static string ToSummaryString<T>( this IEnumerable<T> items, [Optional, DefaultParameterValue(Environment.NewLine)] string delimiter) An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
So is there any workaround? Or are my only options to hard-code it to "\r\n", or make it required?
nullas the default value and switch toEnvironment.NewLineinside the method when the argument isnull?