Export (0) Print
Expand All

ObsoleteAttribute.IsError Property

Gets a Boolean value indicating whether the compiler will treat usage of the obsolete program element as an error.

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

public bool IsError { get; }
/** @property */
public boolean get_IsError ()

public function get IsError () : boolean

Not applicable.

Property Value

true if the obsolete element usage is considered an error; otherwise, false. The default is false.

The following example demonstrates the IsError property by creating an obsolete method, setting its IsError property to false, and running that method. A message is displayed in the console which, inputing the IsError property, shows that the use of the obsolete method is not an error.

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);
      }                     
   } 

}

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

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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft