为什么允许从MemberInfo转换为MethodInfo?

new*_*int -2 .net c# reflection system.reflection

System.Reflection的文档.MemberInfo有以下示例:

foreach (MemberInfo mi in t.GetMembers())  
{
    if (mi.MemberType == MemberTypes.Method)
    {
        foreach (ParameterInfo pi in ((MethodInfo)mi).GetParameters())
Run Code Online (Sandbox Code Playgroud)

注意演员(MethodInfo)mi).MemberInfo并且MethodInfo没有共同的父母,为什么允许演员?

Mar*_*zek 7

MethodInfo继承自的MethodBase继承MemberInfo.

[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class MethodInfo : MethodBase, 
    _MethodInfo
Run Code Online (Sandbox Code Playgroud)
[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class MethodBase : MemberInfo, 
    _MethodBase
Run Code Online (Sandbox Code Playgroud)