using System;
using System.Diagnostics;
namespace ConditionalAttributeExample
{
public class Person
{
//You can use
it but shouldn't
[Obsolete("This Property is obsolete,
use FirstName and LastName instead", false)]
public string FullName
{ get; set; }
public string
FirstName { get; set; }
public string LastName
{ get; set; }
public DateTime BirthDate { get; set; }
//You can't use
it, will create an error
[Obsolete("This method is obsolete, use
GetAge instead", true)]
public int
GetYearsOld()
{
return DateTime.Now.Year - BirthDate.Year;
}
public int GetAge()
{
var Today = DateTime.Now;
var age = Today.AddYears(-BirthDate.Year).Year;
return age;
}
}
class Program
{
static void Main(string[] args)
{
var p = new Person();
//will compile
with warning
p.FullName = "Pawel Chooch";
//will not
complie
p.GetYearsOld();
}
}
}