ObsoleteAttribute, constructeur (String)
Mise à jour : novembre 2007
Initialise une nouvelle instance de la classe ObsoleteAttribute avec un message de solution spécifié.
Assembly : mscorlib (dans mscorlib.dll)
Le tableau suivant montre les valeurs initiales des propriétés d'une instance de ObsoleteAttribute.
L'exemple suivant montre comment utiliser le constructeur ObsoleteAttribute(String). Il contient une fonction qui appelle une méthode désignée comme obsolète, puis tente d'intercepter une exception à l'aide d'un bloc try/catch. La chaîne de paramètre s'affiche comme un message de solution.
using System; public class ObsoleteAttrib_Cons1 { // Mark the method as 'Obsolete' with message as parameter. [ObsoleteAttribute("This function will be removed from future Versions.Use another function 'NewFunction'")] public string OldFunction() { return "This is the String from old function."; } // Create the another function which is replacement to the 'OldFunction'. public string NewFunction() { return "This is the String from new function."; } } public class TestObsolete2 { static void Main(string[] args) { try { ObsoleteAttrib_Cons1 myObsolete = new ObsoleteAttrib_Cons1(); Console.WriteLine(myObsolete.OldFunction()); Console.WriteLine(myObsolete.NewFunction()); } catch(Exception e) { Console.WriteLine("The Exception is :"+e.Message); } } }
import System.*;
public class ObsoleteAttrib_Cons1
{
// Mark the method as 'Obsolete' with message as parameter.
/** @attribute ObsoleteAttribute("This function will be removed from future"
+ "Versions.Use another function 'NewFunction'")
*/
public String OldFunction()
{
return "This is the String from old function.";
} //OldFunction
// Create the another function which is replacement to the 'OldFunction'.
public String NewFunction()
{
return "This is the String from new function.";
} //NewFunction
} //ObsoleteAttrib_Cons1
public class TestObsolete2
{
public static void main(String[] args)
{
try {
ObsoleteAttrib_Cons1 myObsolete = new ObsoleteAttrib_Cons1();
Console.WriteLine(myObsolete.OldFunction());
Console.WriteLine(myObsolete.NewFunction());
}
catch (System.Exception e) {
Console.WriteLine("The Exception is :" + e.get_Message());
}
} //main
} //TestObsolete2
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile pour Smartphone, Windows Mobile pour Pocket PC, Xbox 360
Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.