|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Debug conditional code in class that implements an interface... does it work?internal static readonly instance of the logger which various methods use, e.g.: interface ILogger { void LogDebug(...); void LogInfo(...); void LogError(...); ... } What I did was to create two classes, one in the case where the Logger for that class is off, and the other when it is on. class Logger : ILogger {...} class NullLogger : ILogger { [Conditional("DEBUG")] public void LogDebug(...) { } .... } Now, my question is, the ILogger instance is assigned at runtime. So, if I assign the NullLogger at runtime, which has [Conditional("DEBUG")] will it still for sure not evaluate the parameters passed to the Log method if it is of type NullLogger? For example, with Conditional("DEBUG"), the executeLongMethodToGetValue is not executed. myLog.LogDebug(myObj.executeLongMethodToGetValue()) In this case, myLog is an interface assigned at runtime. If it is of type NullLogger, will this still not evaluate executeLongMethodToGetValue? Thanks! >Now, my question is, the ILogger instance is assigned at runtime. So, No it will evaluate the parameters. The ConditionalAttribute is a>if I assign the NullLogger at runtime, which has [Conditional("DEBUG")] >will it still for sure not evaluate the parameters passed to the Log >method if it is of type NullLogger? compile-time feature. Your code shouldn't even compile. Conditional method are not allowed to implement interface members. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. |
|||||||||||||||||||||||