Mark code with Obsolete and Conditional attribute - CSharp Custom Type

CSharp examples for Custom Type:Attribute

Description

Mark code with Obsolete and Conditional attribute

Demo Code

#define TEST//from  w  w w.j av  a2s .  co m
using System;
using System.Diagnostics;
class Rocket
{
   private double speed;
   private double fuel;
   private double distanceFromMoon;
   public Rocket(double initSpeed, double initFuel, double initDistanceFromMoon)
   {
      speed = initSpeed;
      fuel = initFuel;
      distanceFromMoon = initDistanceFromMoon;
   }
   [Obsolete("Please use Rocket.CurrentState instead")]
   public void CurrentSituation()
   {
      if (fuel > 5000)
         Console.WriteLine("Everything seems OK");
      else
         Console.WriteLine("Houston, I think we've got a problem");
   }
   public void CurrentState()
   {
         Console.WriteLine("Current speed: {0}  Current fuel left: {1}", speed, fuel);
   }
   [Conditional("TEST")]
   public void TestWriteAllDetails()
   {
         Console.WriteLine("Testing: Instance variables: speed: {0}, fuel: {1}, distanceFromMoon: {2}",
         speed, fuel, distanceFromMoon);
   }
}
class ControlCenter
{
      public static void Main()
      {
         Rocket apollo13 = new Rocket(10000, 2000, 20000);
         apollo13.CurrentSituation();
         apollo13.CurrentState();
         apollo13.TestWriteAllDetails();
      }
}

Related Tutorials