blob: a94ca44f242bc629fad80da42964519a343d2cb7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/***************************************************************************************************
Copyright (C) 2025 The Qt Company Ltd.
SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
***************************************************************************************************/
using System.Reflection;
namespace Qt.DotNet.Extensions
{
public static class MemberInfoExtensions
{
public static bool IsOverrideOf(this MemberInfo i, Assembly a)
{
return a.GetTypes().Any(t => i.IsOverrideOf(t));
}
public static bool IsOverrideOf<T>(this MemberInfo i)
{
return i.IsOverrideOf(typeof(T));
}
public static bool IsOverrideOf(this MemberInfo i, Type bt)
{
if (i?.ReflectedType?.IsAssignableTo(bt) is not true)
return false;
if (i is not MethodInfo m)
return false;
if (!m.IsVirtual)
return false;
if ((m.Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot)
return false;
var pars = m.GetParameters()
.Select(p => p.ParameterType)
.ToArray();
if (bt?.GetMethod(m.Name, pars) is not { IsVirtual: true } bm)
return false;
if ((bm.Attributes & MethodAttributes.VtableLayoutMask) != MethodAttributes.NewSlot)
return false;
return true;
}
}
}
|