In Perl I can say
use warnings;
warn "Non-fatal error condition, printed to stderr.";
What is the equivalent of this in C# ASP.NET? Specifically what I'm looking for is something so that other members of my team can know when they're still using a deprecated routine. It should show up at run time when the code path is actually hit, not at compile time (otherwise they'd get warnings about code sitting at a compatibility layer which ought to never run anyway.)
My best option so far is to use Trace, which feels like a bad hack.
1. the third letter of the English alphabet, a consonant. 2. any spoken sound represented by the letter C or c, as in cat, race, or circle.
Compared to C, C++ has significantly more libraries and functions to use. If you're working with complex software, C++ is a better fit because you have more libraries to rely on. Thinking practically, having knowledge of C++ is often a requirement for a variety of programming roles.
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
EDIT: I hadn't seen the bit in the question saying you wanted it at execution time.
The problem about writing out data execution time is that you need to know where to write it. What logging does your application use in general? Use the same form of logging as that, basically.
I would still favour the compile-time option listed below, however - you can turn off specific warnings in the compatibility layer using #pragma warn disable/restore
, but it'll make it a lot easier to spot the problems than hoping someone reads a log file...
Old answer
Use the [Obsolete]
attribute on any type or member. You can decide whether this should end up being a warning or an error. For example:
using System;
class Test
{
static void Main()
{
OldMethod();
BadMethod();
}
[Obsolete("Use something else instead")]
static void OldMethod() {}
[Obsolete("This would destroy your machine!", true)]
static void BadMethod() {}
}
Compiling this gives:
Test.cs(7,9): warning CS0618: 'Test.OldMethod()' is obsolete: 'Use something else instead' Test.cs(8,9): error CS0619: 'Test.BadMethod()' is obsolete: 'This would destroy your machine!'
Ideally, the message should explain what the effects of continuing to use the method would be, and the suggested alternative.
Use ObsoleteAttribute. Decorate it over any method you want to mark as deprecated. They'll get a warning in their errors window, but the app will still compile.
public class Thing
{
[Obsolete]
public void OldMethod() { Console.WriteLine("I'm Old"); }
}
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