How does reflection tell me when a property is hiding an inherited member with the 'new' keyword?

后端 未结 4 739
时光说笑
时光说笑 2020-12-15 18:07

So if I have:

public class ChildClass : BaseClass
{
    public new virtual string TempProperty { get; set; }
}

public class BaseClass
{
    public virtual s         


        
4条回答
  •  执念已碎
    2020-12-15 18:48

    Correction, if you are using VB the property you are looking for is "IsHideBySig". This will be false in the case that the "new" keyword was used to define a method/property.

    In the C# case, both instances are outputted as "hidebysig". Thanks for pointing that out Greg. I didn't realize I only tested this in VB. Here's sample VB code that will repro this behavior.

    Module Module1
    
        Class Foo
            Public Function SomeFunc() As Integer
                Return 42
            End Function
        End Class
    
        Class Bar
            Inherits Foo
            Public Shadows Function SomeFunc() As Integer
                Return 36
            End Function
        End Class
    
        Sub Main()
            Dim type = GetType(Bar)
            Dim func = type.GetMethod("SomeFunc")
            Stop
        End Sub
    
    End Module
    

提交回复
热议问题