Freigeben über


ObsoleteAttribute.Message-Eigenschaft

Ruft die Meldung zum Umgehen des Problems einschließlich einer Beschreibung alternativer Programmelemente ab.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property Message As String
'Usage
Dim instance As ObsoleteAttribute
Dim value As String

value = instance.Message
public string Message { get; }
public:
property String^ Message {
    String^ get ();
}
/** @property */
public String get_Message ()
public function get Message () : String

Eigenschaftenwert

Die Zeichenfolge zur Umgehung des Problems.

Beispiel

Imports System
Imports System.ComponentModel
Imports Microsoft.VisualBasic



Public Class ObsoleteAttribute_Message
   
   ' Mark the property as 'Obsolete' with message and IsError as parameters.
   
<ObsoleteAttribute("This property will be removed from future Versions.Use another property 'MyNewProperty'", False)> _
   Public ReadOnly Property MyOldProperty() As String
      Get
         Return "This is the value of the property"
      End Get
   End Property
   ' Create another property.
   
   Public ReadOnly Property MyNewProperty() As String
      Get
         Return "This is the value of the new property"
      End Get
   End Property
   
   
   ' Get the Properties of the 'ObsoleteAttribute'.  
   Public Sub GetPropertyAttributes()
      ' Retrieve all the attributes.
      Dim attributes As AttributeCollection = TypeDescriptor.GetProperties(Me)("MyOldProperty").Attributes
      
      Dim myAttribute As ObsoleteAttribute = CType(attributes(GetType(ObsoleteAttribute)), ObsoleteAttribute)
      Console.WriteLine(("The Message of the ObsoleteAttribute is :" + ControlChars.Cr + myAttribute.Message))
      Console.WriteLine(("Usage of Obsolete as error is :" + myAttribute.IsError.ToString()))
   End Sub 'GetPropertyAttributes
   
   'Entry point which delegates to C-style main Private Function
   Public Overloads Shared Sub Main()
      Main(System.Environment.GetCommandLineArgs())
   End Sub
   
   
   Overloads Shared Sub Main(args() As String)
      
      Try
         Dim myObsolete As New ObsoleteAttribute_Message()
         Console.WriteLine(("The Message of Old Property is :" + myObsolete.MyOldProperty))
         Console.WriteLine(("The Message of New Property is :" + myObsolete.MyNewProperty))
         Console.WriteLine(ControlChars.Cr + "The Values of ObsoleteAttribute are:")
         myObsolete.GetPropertyAttributes()
      
      Catch e As Exception
         Console.WriteLine(("The Exception is :" + e.Message.ToString()))
      End Try
   End Sub 'Main 
End Class 'ObsoleteAttribute_Message
using System;
using System.ComponentModel;

public class ObsoleteAttribute_Message
{
// Mark the property as 'Obsolete' with message and IsError as parameters.
[ObsoleteAttribute("This property will be removed from future Versions.Use another property 'MyNewProperty'",false)]
   public string MyOldProperty 
   {
      get 
      {
         return "This is the value of the property";
      }
   }
   // Create another property.
   public string MyNewProperty 
   {
      get 
      {
         return "This is the value of the new property";
      }
   }


// Get the Properties of the 'ObsoleteAttribute'.  
public void GetPropertyAttributes()
{
   // Retrieve all the attributes.
   AttributeCollection attributes = TypeDescriptor.GetProperties(this)["MyOldProperty"].Attributes;
       
   ObsoleteAttribute myAttribute = (ObsoleteAttribute)attributes[typeof(ObsoleteAttribute)];
   Console.WriteLine("The Message of the ObsoleteAttribute is :\n"+myAttribute.Message);
   Console.WriteLine("Usage of Obsolete as error is :"+myAttribute.IsError);
}
}

public class TestObsolete4
{
   static void Main(string[] args)
   {                 
      try
      {
         ObsoleteAttribute_Message myObsolete = new ObsoleteAttribute_Message();
         Console.WriteLine("The Message of Old Property is :"+myObsolete.MyOldProperty);
         Console.WriteLine("The Message of New Property is :"+myObsolete.MyNewProperty);
         myObsolete.GetPropertyAttributes();
      }
      catch(Exception e)
      {
         Console.WriteLine("The Exception is :"+e.Message);
      }                     
   } 

}
#using <system.dll>

using namespace System;
using namespace System::ComponentModel;

public ref class ObsoleteAttribute_Message
{
public:

   property String^ MyOldProperty 
   {
      // Mark the property as 'Obsolete' with message and IsError as parameters.

      [ObsoleteAttribute("This property will be removed from future Versions. Use another property 'MyNewProperty'",false)]
      String^ get()
      {
         return "This is the value of the property";
      }
   }

   property String^ MyNewProperty 
   {
      // Create another property.
      String^ get()
      {
         return "This is the value of the new property";
      }
   }

   // Get the Properties of the 'ObsoleteAttribute'.  
   void GetPropertyAttributes()
   {
      // Retrieve all the attributes.
      AttributeCollection^ attributes = TypeDescriptor::GetProperties( this )[ "MyOldProperty" ]->Attributes;
      ObsoleteAttribute^ myAttribute = safe_cast<ObsoleteAttribute^>(attributes[ ObsoleteAttribute::typeid ]);
      Console::WriteLine( "The Message of the ObsoleteAttribute is :\n {0}", myAttribute->Message );
      Console::WriteLine( "Usage of Obsolete as error is : {0}", myAttribute->IsError );
   }
};

int main()
{
   try
   {
      ObsoleteAttribute_Message^ myObsolete = gcnew ObsoleteAttribute_Message;
      Console::WriteLine( "The Message of Old Property is : {0}", myObsolete->MyOldProperty );
      Console::WriteLine( "The Message of New Property is : {0}", myObsolete->MyNewProperty );
      myObsolete->GetPropertyAttributes();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "The Exception is : {0}", e->Message );
   }
}
import System.*;
import System.ComponentModel.*;
public class ObsoleteAttribute_Message
{
    // Mark the property as 'Obsolete' with message and IsError as parameters.
    /** @attribute ObsoleteAttribute("This property will be removed from future"
        + "Versions.Use another property 'MyNewProperty'", false)
     */

    /** @property
     */
    public String get_MyOldProperty()
    {
        return "This is the value of the property";
    } //get_MyOldProperty

    // Create another property.
    
    /** @property 
     */
    public String get_MyNewProperty()
    {
        return "This is the value of the new property";
    } //get_MyNewProperty

    // Get the Properties of the 'ObsoleteAttribute'.  
    public void GetPropertyAttributes()
    {
        // Retrieve all the attributes.
        AttributeCollection attributes = TypeDescriptor.GetProperties(this).
            get_Item("MyOldProperty").get_Attributes();

        ObsoleteAttribute myAttribute = (ObsoleteAttribute)(attributes.
            get_Item(ObsoleteAttribute.class.ToType()));
        Console.WriteLine("The Message of the ObsoleteAttribute is :\n"
            + myAttribute.get_Message());
        Console.WriteLine("Usage of Obsolete as error is :" 
            + myAttribute.get_IsError());
    } //GetPropertyAttributes
} //ObsoleteAttribute_Message

public class TestObsolete4
{
    public static void main(String[] args)
    {
        try {
            ObsoleteAttribute_Message myObsolete = 
                new ObsoleteAttribute_Message();
            Console.WriteLine("The Message of Old Property is :" 
                + myObsolete.get_MyOldProperty());
            Console.WriteLine("The Message of New Property is :"
                + myObsolete.get_MyNewProperty());
            myObsolete.GetPropertyAttributes();
        }
        catch (System.Exception e) {
            Console.WriteLine("The Exception is :" + e.get_Message());
        }
    } //main
} //TestObsolete4

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

ObsoleteAttribute-Klasse
ObsoleteAttribute-Member
System-Namespace