PropertyInfo.CanRead プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > PropertyInfo.CanRead プロパティの意味・解説 

PropertyInfo.CanRead プロパティ

プロパティ読み取ることができるかどうかを示す値を取得します

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

プロパティget アクセサない場合は、読み取ることができません。

CanRead プロパティ取得するには、最初に Type クラス取得します。そして、その Type から PropertyInfo取得します最後にPropertyInfo から CanRead取得します

使用例使用例

2 つプロパティ定義する例を次に示します最初プロパティ読み取り可能で、CanRead プロパティtrue です。2 番目のプロパティ読み取り不可で (get アクセサなし)、CanRead プロパティfalse です。

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

' Define one readable property and one not readable.
Public Class Mypropertya
    Private myCaption As String
 = "A Default caption"

    Public Property Caption() As
 String
        Get
            Return myCaption
        End Get
        Set(ByVal Value As
 String)
            If myCaption <> value Then
                myCaption = value
            End If
        End Set
    End Property
End Class

Public Class Mypropertyb
    Private myCaption As String
 = "B Default caption"

    Public WriteOnly Property
 Caption() As String
        Set(ByVal Value As
 String)
            If myCaption <> value Then
                myCaption = value
            End If
        End Set
    End Property
End Class

Class Mypropertyinfo

    Public Shared Function
 Main() As Integer
        Console.WriteLine(ControlChars.CrLf & "Reflection.PropertyInfo")

        ' Define two properties.
        Dim Mypropertya As New
 Mypropertya()
        Dim Mypropertyb As New
 Mypropertyb()

        Console.Write(ControlChars.Cr & "Mypropertya.Caption
 = " & _
           Mypropertya.Caption)
        ' Mypropertyb.Caption cannot be read because
        ' there is no get accessor.
        ' Get the type and PropertyInfo.
        Dim MyTypea As Type = Type.GetType("Mypropertya")
        Dim Mypropertyinfoa As PropertyInfo
 = MyTypea.GetProperty("Caption")
        Dim MyTypeb As Type = Type.GetType("Mypropertyb")
        Dim Mypropertyinfob As PropertyInfo
 = MyTypeb.GetProperty("Caption")

        ' Get and display the CanRead property.
        Console.Write(ControlChars.CrLf & "CanRead a - "
 & _
           Mypropertyinfoa.CanRead)

        Console.Write(ControlChars.CrLf & "CanRead b - "
 & _
           Mypropertyinfob.CanRead)

        Return 0
    End Function
End Class
using System;
using System.Reflection;
 
// Define one readable property and one not readable.
public class Mypropertya
{
    private string caption = "A Default
 caption";
    public string Caption
    {
        get{return caption;}
        set {if(caption!=value) {caption =
 value;}
        }
    }
}
public class Mypropertyb
{
    private string caption = "B Default
 caption";
    public string Caption
    {
        set{if(caption!=value) {caption = value;}
        }
    }
}
  
class Mypropertyinfo
{
    public static int Main()
    {
        Console.WriteLine("\nReflection.PropertyInfo");
  
        // Define two properties.
        Mypropertya Mypropertya = new Mypropertya();
        Mypropertyb Mypropertyb = new Mypropertyb();
  
        Console.Write("\nMypropertya.Caption = " + Mypropertya.Caption);
        // Mypropertyb.Caption cannot be read, because
        // there is no get accessor.
  
        // Get the type and PropertyInfo.
        Type MyTypea = Type.GetType("Mypropertya");
        PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
        Type MyTypeb = Type.GetType("Mypropertyb");
        PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("Caption");
  
        // Get and display the CanRead property.
        Console.Write("\nCanRead a - " + Mypropertyinfoa.CanRead);
        Console.Write("\nCanRead b - " + Mypropertyinfob.CanRead);
  
        return 0;
    }
}
using namespace System;
using namespace System::Reflection;

// Define one readable property and one not readable.
public ref class Mypropertya
{
private:
   String^ caption;

public:
   Mypropertya()
      : caption( "A Default caption" )
   {}


   property String^ Caption 
   {
      String^ get()
      {
         return caption;
      }

      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};

public ref class Mypropertyb
{
private:
   String^ caption;

public:
   Mypropertyb()
      : caption( "B Default caption" )
   {}


   property String^ Caption 
   {
      void set( String^ value )
      {
         if ( caption != value )
         {
            caption = value;
         }
      }

   }

};

int main()
{
   Console::WriteLine( "\nReflection.PropertyInfo" );
   
   // Define two properties.
   Mypropertya^ mypropertya = gcnew Mypropertya;
   Mypropertyb^ mypropertyb = gcnew Mypropertyb;
   Console::Write( "\nMypropertya->Caption = {0}", mypropertya->Caption
 );
   
   // Mypropertyb.Caption cannot be read, because
   // there is no get accessor.
   // Get the type and PropertyInfo.
   Type^ MyTypea = Type::GetType( "Mypropertya" );
   PropertyInfo^ Mypropertyinfoa = MyTypea->GetProperty( "Caption" );
   Type^ MyTypeb = Type::GetType( "Mypropertyb" );
   PropertyInfo^ Mypropertyinfob = MyTypeb->GetProperty( "Caption" );
   
   // Get and display the CanRead property.
   Console::Write( "\nCanRead a - {0}", Mypropertyinfoa->CanRead );
   Console::Write( "\nCanRead b - {0}", Mypropertyinfob->CanRead );
   return 0;
}

import System.*;
import System.Reflection.*;

// Define one readable property and one not readable.
public class MyPropertyA
{
    private String caption = "A Default caption";

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
    } //get_Caption

    /** @property 
     */
    public void set_Caption (String value)
    {
        if (caption != value) {
            caption = value;
        }
    } //set_Caption
} //MyPropertyA

public class MyPropertyB
{
    private String caption = "B Default caption";

    /** @property 
     */
    public void set_Caption (String value)
    {
        if ( caption != value  ) {
            caption = value;
        }
    } //set_Caption
} //MyPropertyB

class MyPropertyInfo
{   
    public static void main(String[]
 args)
    {
        Console.WriteLine("\nReflection.PropertyInfo");

        // Define two properties.
        MyPropertyA myPropertyA =  new MyPropertyA();
        MyPropertyB myPropertyB =  new MyPropertyB();

        Console.Write(("\nMyPropertyA.Caption = " 
            + myPropertyA.get_Caption()));
        // MyPropertyB.Caption cannot be read, because
        // there is no get accessor.
        // Get the type and PropertyInfo.
        Type myTypeA = Type.GetType("MyPropertyA");
        PropertyInfo myPropertyInfoA = myTypeA.GetProperty("Caption");
        Type myTypeB = Type.GetType("MyPropertyB");
        PropertyInfo myPropertyInfoB = myTypeB.GetProperty("Caption");

        // Get and display the CanRead property.
        Console.Write(("\nCanRead A - " 
            + System.Convert.ToString(myPropertyInfoA.get_CanRead())));
        Console.Write(("\nCanRead B - " 
            + System.Convert.ToString(myPropertyInfoB.get_CanRead())));
    } //main
} //MyPropertyInfo
import System;
import System.Reflection;
 
//Make two properties, one readable and on not readable
 public class Mypropertya
 {
    private var caption : String = "A
 Default caption";
    public function get
 Caption() : String {
        return caption;
    }
    public function set
 Caption(value:String)
    {
        if(caption!=value) {caption = value;}
    }
 }
 public class Mypropertyb
 {
    private var caption : String = "B
 Default caption";
    public function set
 Caption(value:String) {
        if(caption!=value) {caption = value;}
    }
 }
  
 class Mypropertyinfo
 {
    public static function
 Main() : void
    {
       Console.WriteLine("\nReflection.PropertyInfo");
  
       //Build two properties
       var mypropertya : Mypropertya = new
 Mypropertya();
       var mypropertyb : Mypropertyb = new
 Mypropertyb();
  
       Console.Write("\nmypropertya.Caption = " + mypropertya.Caption);
       //Note: Mypropertyb.Caption cannot be read as
       // there is no get accessor
  
       //Get the type and PropertyInfo
       var MyTypea : Type = Type.GetType("Mypropertya");
       var Mypropertyinfoa : PropertyInfo = MyTypea.GetProperty("Caption");
       var MyTypeb : Type = Type.GetType("Mypropertyb");
       var Mypropertyinfob : PropertyInfo = MyTypeb.GetProperty("Caption");
  
       //Get and display the CanRead property
      
       Console.Write("\nCanRead a - " + Mypropertyinfoa.CanRead);
      
       Console.Write("\nCanRead b - " + Mypropertyinfob.CanRead);
  
    }
 }
 Mypropertyinfo.Main();
 /*
 Produces the following output
 
 Reflection.PropertyInfo
 Mypropertya.Caption = A Default caption
 CanRead a - True
 CanRead b - False
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_PropertyInfo.CanRead プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

COM オブジェクトに、CanRead プロパティへのバージョン依存しないアクセス用意されています。

このプロパティは、CLS準拠していません。  

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As _PropertyInfo
Dim value As Boolean

value = instance.CanRead
bool CanRead { get; }
property bool CanRead {
    bool get ();
}
/** @property */
boolean get_CanRead ()

プロパティ
このプロパティ読み取ることができる場合trueそれ以外場合false

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
_PropertyInfo インターフェイス
_PropertyInfo メンバ
System.Runtime.InteropServices 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

PropertyInfo.CanRead プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



PropertyInfo.CanRead プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS