다음을 통해 공유


ObsoleteAttribute 메시지를 제공하십시오.

업데이트: 2007년 11월

TypeName

ProvideObsoleteAttributeMessage

CheckId

CA1041

범주

Microsoft.Design

변경 수준

주요 변경 아님

원인

형식 또는 멤버가 ObsoleteAttribute.Message 속성이 지정되지 않은 System.ObsoleteAttribute 특성으로 표시되어 있습니다.

규칙 설명

ObsoleteAttribute는 더 이상 사용되지 않는 라이브러리 형식 및 멤버를 표시하는 데 사용됩니다. 라이브러리 소비자는 사용되지 않는 것으로 표시된 형식이나 멤버를 사용하지 않도록 해야 합니다. 이러한 형식이나 멤버는 지원되지 않거나 이후의 라이브러리 버전에서 결국 제거될 것이기 때문입니다. ObsoleteAttribute로 표시된 형식 또는 멤버를 컴파일하면 해당 특성의 Message 속성이 표시되어 사용되지 않는 형식 또는 멤버에 대한 정보를 사용자에게 제공합니다. 이 정보에는 일반적으로 사용되지 않는 형식 또는 멤버가 라이브러리 디자이너에서 언제까지 지원되는지에 대한 정보와 대신 사용할 수 있는 형식 또는 멤버에 대한 정보가 들어 있습니다.

위반 문제를 해결하는 방법

이 규칙 위반 문제를 해결하려면 message 매개 변수를 ObsoleteAttribute 생성자에 추가합니다.

경고를 표시하지 않는 경우

Message 속성은 사용되지 않는 형식 또는 멤버에 대한 중요한 정보를 제공하므로 이 규칙에서 경고를 표시하십시오.

예제

다음 예제에서는 제대로 선언된 ObsoleteAttribute가 있는 사용되지 않는 멤버를 보여 줍니다.

Imports System

Namespace DesignLibrary

    Public Class ObsoleteAttributeOnMember

        <ObsoleteAttribute("This property is obsolete and will " & _
             "be removed in a future version. Use the FirstName " & _
             "and LastName properties instead.", False)> _
        ReadOnly Property Name As String
            Get
                Return "Name"
            End Get
        End Property

        ReadOnly Property FirstName As String
            Get
                Return "FirstName"
            End Get
        End Property

        ReadOnly Property LastName As String
            Get
                Return "LastName"
            End Get
        End Property

    End Class

End Namespace
using System;

namespace DesignLibrary
{
    public class ObsoleteAttributeOnMember
    {
        [ObsoleteAttribute("This property is obsolete and will " +
             "be removed in a future version. Use the FirstName " +
             "and LastName properties instead.", false)]
        public string Name
        {
            get
            {
                return "Name";
            }
        }

        public string FirstName
        {
            get
            {
                return "FirstName";
            }
        }

        public string LastName
        {
            get
            {
                return "LastName";
            }
        }

    }
}
using namespace System;

namespace DesignLibrary
{
    public ref class ObsoleteAttributeOnMember
    {
    public:
        [ObsoleteAttribute("This property is obsolete and will " 
            "be removed in a future version. Use the FirstName " 
            "and LastName properties instead.", false)]
        property String^ Name
        {
            String^ get()
            {
               return "Name";
            }
        }

        property String^ FirstName
        {
            String^ get()
            {
               return "FirstName";
            }
        }

        property String^ LastName
        {
            String^ get()
            {
               return "LastName";
            }
        }
    };
}

참고 항목

참조

System.ObsoleteAttribute