代わりに使用できるプログラム要素の説明などを含む代替手段メッセージを取得します。
Public ReadOnly Property Message As String
[C#]
public string Message {get;}
[C++]
public: __property String* get_Message();
[JScript]
public function get Message() : String;
プロパティ値
代替手段を説明する文字列。
使用例
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
[C#]
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);
}
}
}
[C++]
#using <mscorlib.dll>
#using <system.dll>
using namespace System;
using namespace System::ComponentModel;
public __gc class ObsoleteAttribute_Message
{
public:
// Mark the property as 'Obsolete' with message and IsError as parameters.
[ObsoleteAttribute(S"This property will be removed from future Versions. Use another property 'MyNewProperty'", false)]
__property String* get_MyOldProperty()
{
return S"This is the value of the property";
}
// Create another property.
__property String* get_MyNewProperty()
{
return S"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)->Item[S"MyOldProperty"]->Attributes;
ObsoleteAttribute* myAttribute = __try_cast<ObsoleteAttribute*>(attributes->Item[__typeof(ObsoleteAttribute)]);
Console::WriteLine(S"The Message of the ObsoleteAttribute is :\n {0}", myAttribute->Message);
Console::WriteLine(S"Usage of Obsolete as error is : {0}", __box(myAttribute->IsError));
}
};
int main()
{
try {
ObsoleteAttribute_Message* myObsolete = new ObsoleteAttribute_Message();
Console::WriteLine(S"The Message of Old Property is : {0}", myObsolete->MyOldProperty);
Console::WriteLine(S"The Message of New Property is : {0}", myObsolete->MyNewProperty);
myObsolete->GetPropertyAttributes();
} catch (Exception* e) {
Console::WriteLine(S"The Exception is : {0}", e->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard