What does the C # equivalent of perl mean?

In Perl, I can say

use warnings;
warn "Non-fatal error condition, printed to stderr.";

What is equivalent to this in C # ASP.NET? In particular, what I'm looking for is something that other members of my team may know when they are still using the outdated procedure. It should appear at runtime, when the code path actually hits, and not at compile time (otherwise they will receive warnings about code sitting at the compatibility level, which should never be run anyway.)

My best option so far is to use Trace, which seems like a bad hack.

+5
source share
7 answers

Trace.TraceWarning , ObsoleteAttribute .

.

  • , ObsoleteAttribute []
  • , ObsoleteAttribute .
  • , , IL [] , .

, [Obsolete], .

, , [], , :

#pragma warning disable 618

. [], .

+2

ObsoleteAttribute. , . , .

public class Thing
{
     [Obsolete]
     public void OldMethod() { Console.WriteLine("I'm Old"); }
}
+6

EDIT: , , .

, , . ? , .

- , , #pragma warn disable/restore, , , - ...


[Obsolete] . , . :

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() {}
}

:

Test.cs(7,9): CS0618: 'Test.OldMethod()' : ' - "Test.cs(8,9): CS0619: 'Test.BadMethod()' :" !

, , , .

+4

FYI # , ; [] , .

+2

warn __WARN__, STDERR Console.Error.WriteLine().

, , , - , , . , .

+2

, Trace - . , , , Fail ( assert).

private void SomeOldMethod()
{
  Trace.Fail("You shouldn't call this method"); // <-- this will bring up an assert dialog
  Trace.TraceWarning("You shouldn't call this method");
  Trace.TraceError("You shouldn't call this method");
}
+1

, #, - , , ( intellisense) bool , . 100% , , , perl

[Obsolete("A message",false)]
0
source

All Articles