_MethodBase.IsHideBySigとは? わかりやすく解説

MethodBase.IsHideBySig プロパティ

派生クラスで、正確に同じシグネチャを持つ同じ種類メンバだけが隠しメンバになるかどうかを示す値を取得します

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

解説解説
使用例使用例

オーバーロードされたメソッドを持つ基本クラスと、オーバーロードいずれかを隠す派生クラスを含むコード例次に示します。このコード例Visual Basic バージョンでは、IsHideBySig プロパティ派生クラスメンバに対して false返します。このコード例C# バージョンでは、派生クラスメンバに対して true返します

Imports System
Imports System.Reflection

' The base class B contains an overloaded method M.
'
Public Class B
    Public Overridable Sub
 M()
        Console.WriteLine("B's M()")
    End Sub
    Public Overridable Sub
 M(ByVal x As Integer)
        Console.WriteLine("B's M({0})", x)
    End Sub
End Class

' The derived class D hides the inherited method M.
'
Public Class D
    Inherits B
    Shadows Public Sub M(ByVal
 i As Integer)
        Console.WriteLine("D's M({0})", i)
    End Sub
End Class

Public Class Test
    Public Shared Sub Main()
        Dim dinst As New
 D()
        ' In Visual Basic, the method in the derived class hides by
        ' name, rather than by signature.  Thus, although a list of
 all the 
        ' overloads of M shows three overloads, only one can be called
 from
        ' class D.  
        '
        Console.WriteLine("------ List the overloads of M in the
 derived class D ------")
        Dim t As Type = dinst.GetType()
        For Each minfo As
 MethodInfo In t.GetMethods()
            If minfo.Name = "M"
 Then Console.WriteLine( _
                "Overload of M: {0}  IsHideBySig = {1}, DeclaringType
 = {2}", _
                minfo, minfo.IsHideBySig, minfo.DeclaringType)
        Next

        ' The method M in the derived class hides the method in B.
        '
        Console.WriteLine("------ Call the overloads of M available
 in D ------")
        ' The following line causes a compile error, because both overloads
        ' in the base class are hidden.  Contrast this with C#, where
 only 
        ' one of the overloads of B would be hidden.
        'dinst.M()
        dinst.M(42)
        
        ' If D is cast to the base type B, both overloads of the 
        ' shadowed method can be called.
        '
        Console.WriteLine("------ Call the shadowed overloads
 of M ------")
        Dim binst As B = dinst
        binst.M()
        binst.M(42)         
    End Sub 'Main
End Class 'Test

' This code example produces the following output:
' ------ List the overloads of M in the derived class D ------
' Overload of M: Void M(Int32)  IsHideBySig = False, DeclaringType =
 B
' Overload of M: Void M()  IsHideBySig = False, DeclaringType = B
' Overload of M: Void M(Int32)  IsHideBySig = False, DeclaringType =
 D
' ------ Call the overloads of M available in D ------
' D's M(42)
' ------ Call the shadowed overloads of M ------
' B's M()
' B's M(42)
using System;
using System.Reflection;

// The base class B contains an overloaded method M.
//
public class B
{
    public virtual void M()
    {
        Console.WriteLine("B's M()");
    }
    public virtual void M(int
 x)
    {
        Console.WriteLine("B's M({0})", x);
    }
}

// The derived class D hides one overload of the inherited 
// method M.
//
public class D:
    B
{
    new public void M(int
 i)
    {
        Console.WriteLine("D's M({0})", i);
    }
}

public class Test
{
    public static void Main()
    {
        D dinst = new D();
        // In C#, the method in the derived class hides by name and
 by
        // signature, so the overload in the derived class hides only
 one
        // of the overloads in the base class.
        //
        Console.WriteLine("------ List the overloads of M in
 the derived class D ------");
        Type t = dinst.GetType();
        foreach( MethodInfo minfo in t.GetMethods()
 )
        {
            if (minfo.Name=="M") {Console.WriteLine("Overload
 of M: {0}  IsHideBySig = {1}, DeclaringType = {2}", minfo, minfo.IsHideBySig,
 minfo.DeclaringType);}
        }

        // The method M in the derived class hides one overload of the
 
        // method in B.  Contrast this with Visual Basic, which hides
 by
        // name instead of by name and signature.  In Visual Basic,
 the
        // parameterless overload of M would be unavailable from D.
        //
        Console.WriteLine("------ Call the overloads of M available in
 D ------");
        dinst.M();
        dinst.M(42);
        
        // If D is cast to the base type B, both overloads of the 
        // shadowed method can be called.
        //
        Console.WriteLine("------ Call the shadowed overloads of M ------");
        B binst = dinst;
        binst.M();
        binst.M(42);
    } //Main
} //Test

/* This code example produces the following output:

------ List the overloads of M in the derived class
 D ------
Overload of M: Void M(Int32)  IsHideBySig = True, DeclaringType = B
Overload of M: Void M()  IsHideBySig = True, DeclaringType = B
Overload of M: Void M(Int32)  IsHideBySig = True, DeclaringType = D
------ Call the overloads of M available in D ------
B's M()
D's M(42)
------ Call the shadowed overloads of M ------
B's M()
B's M(42)
*/

using namespace System;
using namespace System::Reflection;

// The base class Parent contains an overloaded method PrintCall.
//
public ref class Parent
{
public:
    virtual void PrintCall()
    {
        Console::WriteLine("Parent's PrintCall()");
    }
public:
    virtual void PrintCall(int x)
    {
        Console::WriteLine("Parent's PrintCall({0})", x);
    }
};

// The derived class Child hides one overload of the inherited 
// method PrintCall.
//
public ref class Child : public
 Parent
{
public:
    void PrintCall(int i) new
    {
        Console::WriteLine("Child's PrintCall({0})", i);
    }
};

int main()
{
    Child^ childInstance = gcnew Child();

    // In C#, the method in the derived class hides by name and by
    // signature, so the overload in the derived class hides only one
    // of the overloads in the base class.
    //
    Console::WriteLine("------ List the overloads of PrintCall in
 the " +
        "derived class Child ------");
    Type^ t = childInstance->GetType();
    for each(MethodInfo^ minfo in t->GetMethods())
    {
        if (minfo->Name == "PrintCall")
        {
            Console::WriteLine("Overload of PrintCall: {0}" +
                " IsHideBySig = {1}, DeclaringType = {2}", 
                minfo, minfo->IsHideBySig, minfo->DeclaringType);
        }
    }

    // The method PrintCall in the derived class hides one overload
 of the 
    // method in Parent.  Contrast this with Visual Basic, which hides
 by
    // name instead of by name and signature.  In Visual Basic, the
    // parameterless overload of PrintCall would be unavailable from
 Child.
    //
    Console::WriteLine(
        "------ Call the overloads of PrintCall available in
 Child ------");
    childInstance->PrintCall();
    childInstance->PrintCall(42);

    // If Child is cast to the base type Parent, both overloads of the
 
    // shadowed method can be called.
    //
    Console::WriteLine(
        "------ Call the shadowed overloads of PrintCall ------");
    Parent^ parentInstance = childInstance;
    parentInstance->PrintCall();
    parentInstance->PrintCall(42);
}

/* This code example produces the following output:

------ List the overloads of PrintCall in the derived class
 Child ------
Overload of PrintCall: Void PrintCall(Int32) IsHideBySig = True, DeclaringType =
 Child
Overload of PrintCall: Void PrintCall() IsHideBySig = True, DeclaringType = Parent
Overload of PrintCall: Void PrintCall(Int32) IsHideBySig = True, DeclaringType =
 Parent
------ Call the overloads of PrintCall available in Child ------
Parent's PrintCall()
Child's PrintCall(42)
------ Call the shadowed overloads of PrintCall ------
Parent's PrintCall()
Parent's PrintCall(42)

*/

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

// The base class B contains an overloaded method M.
//
public class B
{
    public void M()
    {
        Console.WriteLine("B's M()");
    } //M

    public void M(int x)
    {
        Console.WriteLine("B's M({0})", (Int32)x);
    } //M
} //B

// The derived class D hides one overload of the inherited 
// method M.
//
public class D extends B
{
    public void M(int i)
    {
        Console.WriteLine("D's M({0})", (Int32)i);
    } //M
} //D

public class Test
{
    public static void main(String[]
 args)
    {
        D dInst = new D();
        // In VJ#, the method in the derived class hides by name and
 by
        // signature, so the overload in the derived class hides only
 one
        // of the overloads in the base class.
        //
        Console.WriteLine("------ List the overloads of M in
 the "
            + "derived class D ------");
        Type t = dInst.GetType();
        for (int iCtr = 0; iCtr < t.GetMethods().get_Length();
 iCtr++) {
            MethodInfo mInfo = (MethodInfo)t.GetMethods().get_Item(iCtr);
            if (mInfo.get_Name().Equals("M")) {
                Console.WriteLine("Overload of M: {0}  IsHideBySig = {1}, "
                    + "DeclaringType = {2}", mInfo, 
                    (System.Boolean)mInfo.get_IsHideBySig(), 
                    mInfo.get_DeclaringType().ToString());
            }
        }
        // The method M in the derived class hides one overload of the
 
        // method in B.  Contrast this with Visual Basic, which hides
 by
        // name instead of by name and signature.  In Visual Basic,
 the
        // parameterless overload of M would be unavailable from D.
        //
        Console.WriteLine("------ Call the overloads of M available in
 D ------");
        dInst.M();
        dInst.M(42);
        // If D is cast to the base type B, both overloads of the 
        // shadowed method can be called.
        //
        Console.WriteLine("------ Call the shadowed overloads of M ------");
        B bInst = dInst;
        bInst.M();
        bInst.M(42);
    } //main 
} //Test
/* This code example produces the following output:

------ List the overloads of M in the derived class
 D ------
Overload of M: Void M(Int32)  IsHideBySig = True, DeclaringType = D
Overload of M: Void M()  IsHideBySig = True, DeclaringType = B
------ Call the overloads of M available in D ------
B's M()
D's M(42)
------ Call the shadowed overloads of M ------
B's M()
D's M(42)

*/

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

_MethodBase.IsHideBySig プロパティ

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

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

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

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

Dim instance As _MethodBase
Dim value As Boolean

value = instance.IsHideBySig
bool IsHideBySig { get; }
property bool IsHideBySig {
    bool get ();
}
/** @property */
boolean get_IsHideBySig ()
function get IsHideBySig () : boolean

プロパティ
メンバシグネチャ隠される場合trueそれ以外場合false

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



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

辞書ショートカット

すべての辞書の索引

「_MethodBase.IsHideBySig」の関連用語

_MethodBase.IsHideBySigのお隣キーワード
検索ランキング

   

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



_MethodBase.IsHideBySigのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS