I have a Portable Class Library with a class PCLDebug
:
public static class PCLDebug {
public static Action<string> LogLine { get; set; }
}
What I want to do is set things up once in the outer project, then be able to call LogLine
within the PCL to print stuff to the VS Output window. Here is my attempt:
MyPCL.PCLDebug.LogLine = System.Diagnostics.Debug.WriteLine;
The problem here is that the compiler complains, because System.Diagnostics.Debug.WriteLine has a conditional attribute of Debug:
Cannot create delegate with 'System.Diagnostics.Debug.WriteLine(string)' because it has a Conditional attribute
I am actually fine with it if the LogLine
call only works in the debugging environment. But how do I keep the compiler happy?
You could try wrapping it in a lambda function:
MyPCL.PCLDebug.LogLine = s => { System.Diagnostics.Debug.WriteLine( s ); };
you can use this alternative notation too:
MyPCL.PCLDebug.LogLine = delegate(string text) { System.Diagnostics.Debug.WriteLine(text); };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With